Question about file objects...

Andre Engels andreengels at gmail.com
Wed Dec 2 09:33:40 EST 2009


On Wed, Dec 2, 2009 at 3:14 PM, J <dreadpiratejeff at gmail.com> wrote:
> Something that came up in class...
>
> when you are pulling data from a file using f.next(), the file is read
> one line at a time.
>
> What was explained to us is that Python iterates the file based on a
> carriage return as the delimiter.
> But what if you have a file that has one line of text, but that one
> line has 16,000 items that are comma delimited?
>
> Is there a way to read the file, one item at a time, delimited by
> commas WITHOUT having to read all 16,000 items from that one line,
> then split them out into a list or dictionary??

If f is a file object, f.read(1) will get the next byte of the file.
Get single-character strings that way until you arrive at a ",", then
concatenate what you have received before that.

-- 
André Engels, andreengels at gmail.com



More information about the Python-list mailing list