Populating a list

A. Keyton Weissinger keyton at weissinger.org
Sun Dec 9 20:01:48 EST 2001

So we're clear. You can either do it this way:

states = []
f=open('/home/mlorfeld/states.txt', 'r+').readlines()
for i in f:
print states

The rstrip() method, as you can probably guess, strips white spaces from the
RIGHT end of the string.

or (from Mr. Martelli -- I like this one better):

f = open('/home/mlorfeld/states.txt', 'r+')
states = [ line[:-1] for line in f.readlines() ]

Sorry for the misinformation, folks.


More information about the Python-list mailing list