Newbie DATA STRUCTURES Question.

David Goodger dgoodger at bigfoot.com
Sat Jul 29 00:10:03 EDT 2000


on 2000-07-28 22:57, gbp (gpepice1 at nycap.rr.com) wrote:
> I need to write a script to read a large text file into a structured
> format.

    file = open('filename', 'r')  # read-only, text mode
    lines = file.readlines()

This gives you a list of strings, one per line from the file. Now, what
would you like to do with the text?

For an alternate method, look at the "fileinput" module (standard library).
It provides an interface kind of like Perl I/O loops.

As for pointers, you must unlearn what you have learned. :> In Python,
everything is an object, variables are just names that are bound to objects,
and pointers are implicit, so you don't have to reference or dereference
anything. Want a list of lists? A list of dictionaries (hashes/associative
arrays) containing lists of complex numbers and strings? No problem. Give us
the details of where you're stuck and we'll help.

-- 
David Goodger    dgoodger at bigfoot.com    Open-source projects:
 - The Go Tools Project: http://gotools.sourceforge.net
 (more to come!)




More information about the Python-list mailing list