This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author samwyse
Recipients samwyse
Date 2012-10-03.21:30:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349299808.15.0.576554890473.issue16122@psf.upfronthosting.co.za>
In-reply-to
Content
I'm once again frustrated by a third-party module that only accepts filenames, not already-opened file-like objects.  This prevents me from passing in StringIO objects or any of the standard file streams.  Currently, *open()* function accepts strings or (in Python 3.X) integers.  I propose that *open()* accept "file-like" objects, either returning them unchanged, or by returning a wrapper object.  While there are many different types of file-like objects, they all have one characteristic in common: the presence of a .close() method.

A non-wrapped version of open() could be as simple as this:

  try:
    file = original_open(name, mode, buffering)
  except TypeError:
    if hasattr(name, 'close'):
        return name
    raise

Returning a wrapper object would be slightly more complicated, but would allow the wrapped object to remain open even after the wrapper is closed.
History
Date User Action Args
2012-10-03 21:30:08samwysesetrecipients: + samwyse
2012-10-03 21:30:08samwysesetmessageid: <1349299808.15.0.576554890473.issue16122@psf.upfronthosting.co.za>
2012-10-03 21:30:08samwyselinkissue16122 messages
2012-10-03 21:30:07samwysecreate