How python skips the beginning of an object that can be aligned
This article will explain in detail how python skips the beginning of the object. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Skip the beginning of an object that can be aligned
Sometimes you have to deal with files at the beginning of unwanted lines (such as comments). "itertools" once again provides a simple solution:
String_from_file = "" / / Author:. / / License:. / Date:. Actual content... "" Import itertools for line in itertools.dropwhile (lambda line: line.startswith ("/ /"), string_from_file.split ("): print (line)
This code only prints the content after the initial comment section. This approach is useful if we only want to discard the first part of the iterable object (the comment line that begins in this example) without knowing how long we want it to be.
This is the end of the article on "how to skip the beginning of the object in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.