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.
just do a split on the line by comment then get the first element eg
line.split(";")[0]
I have not tested this with python but I use similar code else where.
import re content = open(r'c:\temp\test.txt', 'r').read() content = re.sub(";.+", "\n")