Proposed extension to file constructor

Jeff Epler jepler at unpythonic.net
Tue Jun 3 21:47:41 CEST 2003


On Tue, Jun 03, 2003 at 02:40:28PM -0500, Skip Montanaro wrote:
> 
>     taral> I needed to extend popen functionality, so I modified the file
>     taral> constructor to optionally take a file descriptor. It was, in my
>     taral> opinion, the minimum way to do it while preserving isinstance(x,
>     taral> file).
> 
> Where are you getting file descriptors?  What's wrong with using os.fdopen
> to wrap a file descriptor in a file object?
> 
>     fdopen(...)
>         fdopen(fd [, mode='r' [, bufsize]]) -> file_object
> 
>         Return an open file object connected to a file descriptor.

.. but maybe this is the natural interpretation of file(i) when
isinstance(i, int).

.. and maybe the natural interpretation of file(f) when isinstance(f,
int) is file(os.dup(f.fileno())) (assuming the above file(i) behavior)

.. and maybe the natural interpretation of file("-") is sys.stdin, and
file("-", "w") is sys.stdout.

.. and maybe I should just shut up now.

Jeff
PS I'm not sure if I'm serious, sarcastic, or maybe even doing a bad job
of trolling.  Let me know if you can tell.  I think I'm half-serious
about the first two items.





More information about the Python-list mailing list