Let\'s say I\'m parsing a file, which uses ; as the comment character. I don\'t want to parse comments. So if I a line looks like this:
;
example.com.
Here is another way :
In [6]: line = "foo;bar" In [7]: line[:line.find(";")] + "\n" Out[7]: 'foo\n'