Is there an existing way to read any files with python already ignoring characters that are to the right of a comment character (for example, #
)?
For example, consider the file
# this is a comment
0, 6, 7 # this is a comment
5, 6, 7 # this is a comment
7, 6 # this is a comment
I'm looking for something that could already be called as
file.readcomlines()
#or
readcomlines(file)
and return
['0, 6, 7 ', '5, 6, 7 ', '7, 6 ']
Is there such a thing in python or I'm going to have to program this function manually? Web search was of no help at all.