fileno() not supported in Python 3.1

Cameron Simpson cs at zip.com.au
Fri Nov 14 07:31:32 CET 2014


On 14Nov2014 13:52, Ben Finney <ben+python at benfinney.id.au> wrote:
>satishmlmlml at gmail.com writes:
>> How to get file descriptor number for the following:
>> sys.stdin
>> sys.stdout
>> sys.stderr
>
>Why do you need this? What are you intending to do?

In fairness, who cares? It is a basic and reasonable thing to do. I did it only 
last night: I wanted to know if stderr was a tty or pipe, versus a regular 
file, as I wanted to special case some error formatting (loosely speaking, 
default automatic people-friendliness versus log file verbosity).

I know that why people want to do things is important, as they may be choosing 
the wrong approach. But the above question seems very simple and very basic: he 
seems unable to get the OS file descriptor number from the standard streams, 
and this is surprising.

I think he even started the thead with almost a transcript of the failure, and 
backed off the the above abstraction when someone complained.

Cheers,
Cameron Simpson <cs at zip.com.au>

| Alain van der Heide                      |  This is the way the world ends  |
| avdh at dazixco.ingr.com                    |  This is the way the world ends  |
| "The opinions expressed above are mine-  |  This is the way the world ends  |
| mineminemine, and you can't have them."  |  Not with a bang, but with a whi

segmentation fault
core dumped



More information about the Python-list mailing list