Message171908
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. |
|
Date |
User |
Action |
Args |
2012-10-03 21:30:08 | samwyse | set | recipients:
+ samwyse |
2012-10-03 21:30:08 | samwyse | set | messageid: <1349299808.15.0.576554890473.issue16122@psf.upfronthosting.co.za> |
2012-10-03 21:30:08 | samwyse | link | issue16122 messages |
2012-10-03 21:30:07 | samwyse | create | |
|