Populating a list

A. Keyton Weissinger keyton at weissinger.org
Sun Dec 9 19:56:19 EST 2001


D'OH!

Sorry. Like I said. I'm not all that adept either....

K

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Luke
Sent: Sunday, December 09, 2001 7:24 PM
To: python-list at python.org
Subject: Re: Populating a list


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

f.close() will fail because f is a list, not a file object.

 > f=open('/home/mlorfeld/states.txt', 'r+').readlines()

This line while being fine, probably isn't the best idea in the interest 
of clairity as f traditionally denotes a file pointer, not a list.  I 
would give it a more meaningful name.

-- 
http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list