CSV module and "fileobj"

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Mar 16 09:37:51 EDT 2007


Jon Clements a écrit :
> Hi Group,
> 
> If I have a CSV reader that's passed to a function, is it possible for
> that function to retrieve a reference to the "fileobj" like object
> that was passed to the reader's __init__? For instance, if it's using
> an actual file object, then depending on the current row, I'd like to
> open the file object again, seek to the current position, then create
> a csv.reader on that, exhaust it until a certain point, then return.
> ie, leaving the passed iterator intact and ready to carry on as
> normal.
> 
> (And yes, I know passing in the source object is probably easier --
> assume a constraint that I can't...)
> 

As Skip pointed out, this won't work that way. There might be a possible 
workaround using itertools.tee and eventually StringIO.

My 2 cents



More information about the Python-list mailing list