Low level file descriptors and high-level Python files

Laura Creighton lac at openend.se
Tue Sep 1 13:41:42 EDT 2015


In a message of Wed, 02 Sep 2015 00:57:22 +1000, "Steven D'Aprano" writes:
>Let's suppose somebody passes me a file descriptor to work with. It could
>come from somewhere else, but for the sake of discussion let's pretend I
>create it myself this way:

>Q1:  In this example, I know that I opened the fd in write mode, because I
>did it myself. But since I'm not actually opening it, how do I know what
>mode to use in the call to fdopen? Is there something I can call to find
>out what mode a file descriptor has been opened with?

for POSIX things use fnclt.  YOu have to parese the bits yourself
and I always have to look that up to see what the grubby details
are.  No clue what you do on windows.

Don't go around closing things you don't know are open.  They
could be some other processes' thing.

Laura



More information about the Python-list mailing list