text file

Tim Hammerquist tim at vegeta.ath.cx
Fri Dec 21 23:58:16 CET 2001

friend4allin <friend4allin at yahoo.com> graced us by uttering:
> I need some help regarding this one.I am reading contents from a 
> textfile and then putting the same into data structures say a list. 
> can any one you help me with this...

If I understand you correctly, you want to populate a list with the
contents of a textfile, such as one line per element of list/array?

f = open('textfile', 'r')
lines = f.readlines()

Watch out if your textfile gets too large, though.

If this isn't what you want, try giving us an example of what you have
and what you want it to be afterwards.

Tim Hammerquist
What about WRITING it first and rationalizing it afterwords?  :-)
    -- Larry Wall in <8162 at jpl-devvax.JPL.NASA.GOV>

More information about the Python-list mailing list