Newby Question for reading a file

Mike Driscoll kyosohma at
Thu Feb 19 19:40:36 CET 2009

On Feb 19, 12:32 pm, "steven.oldner" <steven.old... at> wrote:
> Simple question but I haven't found an answer.  I program in ABAP, and
> in ABAP you define the data structure of the file and move the file
> line into the structure, and then do something to the fields.  That's
> my mental reference.
> How do I separate or address each field in the file line with PYTHON?
> What's the correct way of thinking?
> Thanks!

I don't really follow what you mean since I've never used ABAP, but
here's how I typically read a file in Python:

f = open("someFile.txt")
for line in f:
    # do something with the line
    print line

Of course, you can read just portions of the file too, using something
like this:

Which will read 64 bytes. For more info, check the following out:

 - Mike

More information about the Python-list mailing list