I am parsing a big text file, and if I could only somehow read lines without the ‘\n’ symbol my life would be a lot easier. For example:
Hello
World
is returned by python’s readLines() as {'Hello\n','World\n'}, while I need to get {'Hello','World'}. Is there a way to only read printed chars?
I know it can be done using regex, but I hope there’s a more simple way to do it.
Thanks!
You can use the
rstrip()function to eliminate trailing newlines. For your specific example:More information here: http://docs.python.org/library/string.html
You might consider getting rid of the newline as you read the file: