MyTetra Share
Делитесь знаниями!
Время создания: 31.08.2017 21:01
Текстовые метки: knowledge
Раздел: Python - Потоки
Запись: xintrea/mytetra_db_mcold/master/base/150349326939tyo0fm7w/text.html на



I am sorry if it's very basic or already asked before (I googled but couldn't find a simple & satisfactory explanation).

I want to know what sys.stdin.fileno() is?

I saw it in a code and didn't understand what it does. Here's the actual code block,

fileno = sys.stdin.fileno()

if fileno is not None:

new_stdin = os.fdopen(os.dup(fileno))

I just executed print sys.stdin.fileno() in my python command line and it returned 0.

I also searched google, and this (  is the reference I could find, but it also only says,

fileno() -> integer "file descriptor".

This is needed for lower-level file interfaces, such

So, what exactly does it mean?

python  file-access

s hareimprove this question

asked Aug 25 '15 at 8:50





That means that it's needed for lower-level file interfaces (such as It's the low level identifier for the file (and it may not be applicable on all platforms), traditionally standard-in has descriptor 0, standard-out 1 and standard-err 2 and other files has descriptors >2. os.dup duplicates a descriptor (creates a low-level identifier for a copy of the file), and fdopen creates a high-level object from a low-level descriptor. – skyking Aug 25 '15 at 8:57  

add a comment

3 Answers

a ctiveoldest votes

Не нашли ответ? З адайте вопрос на Stack Overflow на русском.

up vote6down voteaccepted

File descriptor is a low-level concept, it's an integer that represents an open file. Each open file is given a unique file descriptor.

In Unix, by convention, the three file descriptors 01, and 2 represent standard input, standard output, and standard error, respectively.

>>> import sys

>>> sys.stdin.fileno()


>>> sys.stdout.fileno()


>>> sys.stderr.fileno()


MyTetra Share v.0.58
Яндекс индекс цитирования