file access - What is sys.stdin.fileno() in python -
i sorry if it's basic or asked before (i googled couldn't find simple & satisfactory explanation).
i want know sys.stdin.fileno()
is?
i saw in code , didn't understand does. here's actual code block,
fileno = sys.stdin.fileno() if fileno not none: new_stdin = os.fdopen(os.dup(fileno))
i executed print sys.stdin.fileno()
in python command line , returned 0
.
i searched google, , this (nullage.com) reference find, says,
fileno() -> integer "file descriptor".
this needed lower-level file interfaces, such os.read().
so, mean?
file descriptor low-level concept, it's integer represents open file. each open file given unique file descriptor.
in unix, convention, 3 file descriptors 0
, 1
, , 2
represent standard input, standard output, , standard error, respectively.
>>> import sys >>> sys.stdin.fileno() 0 >>> sys.stdout.fileno() 1 >>> sys.stderr.fileno() 2
Comments
Post a Comment