CSV module and "fileobj"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Clements

    #1

    CSV module and "fileobj"

    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...)

    Cheers,

    Jon.

  • skip@pobox.com

    #2
    Re: CSV module and "fileobj&q uot;


    JonIf I have a CSV reader that's passed to a function, is it possible
    Jonfor that function to retrieve a reference to the "fileobj" like
    Jonobject that was passed to the reader's __init__?

    Nope, that isn't exposed from the C type.

    Skip

    Comment

    • Bruno Desthuilliers

      #3
      Re: CSV module and "fileobj&q uot;

      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

      Comment

      Working...