Q:

Python Remove Whitespace

This is my first question so forgive me if this is not a well formed question but I am trying to read the contents of a file in Python.
So far I could print the contents of the file but there are whitespaces at the beginning and end of each line and I don't want the whitespaces on the beginning. How do I do that.
with open('dump.txt','r') as f:
    print f.read()

Thanks!

A:

You can do something like this. 
with open('dump.txt','r') as f:
    for line in f:
        print line.lstrip()

lstrip specifically removes the whitespace from the beginning of the string.
PS. read gives you the whole content of the file, you better operate on the line level by readline
UPDATE:
As pointed out, there are severals ways of doing this and one other way is to read the contents of the file via readlines and iterate through that list to strip the whitespace.

