This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.sameopenfile reports that standard streams are the same
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: pjenvey, ryles
Priority: normal Keywords:

Created on 2009-05-22 00:56 by ryles, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg88174 - (view) Author: Ryan Leslie (ryles) Date: 2009-05-22 00:56
Python 2.6.1 (r261:67515, Apr  2 2009, 18:25:55)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, os
>>> os.path.sameopenfile(sys.stdin.fileno(), sys.stdout.fileno())
True
>>> os.path.sameopenfile(sys.stdout.fileno(), sys.stderr.fileno())
True
>>> null = open(os.devnull)
>>> os.path.sameopenfile(sys.stdin.fileno(), null.fileno())
False
>>> # That worked.
msg88175 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2009-05-22 01:45
They are the same file, namely your tty

Python 2.6 (r26:66714, Oct  8 2008, 22:16:30) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> [os.ttyname(fp.fileno()) for fp in sys.stdin, sys.stdout, sys.stderr]
['/dev/ttys002', '/dev/ttys002', '/dev/ttys002']
msg88178 - (view) Author: Ryan Leslie (ryles) Date: 2009-05-22 03:34
Thanks for the quick response, Philip. Makes even more sense now that I see:

Python 2.6.1 (r261:67515, Apr  2 2009, 18:25:55)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> open('/dev/stdout').readline()
hello
'hello\n'
>>> open('/dev/stdin').readline()
hello
'hello\n'
>>>
History
Date User Action Args
2022-04-11 14:56:49adminsetgithub: 50332
2009-05-22 03:35:31rylessetstatus: open -> closed
2009-05-22 03:35:01rylessetstatus: closed -> open

messages: + msg88178
2009-05-22 01:58:45r.david.murraysetstatus: open -> closed
resolution: not a bug
stage: resolved
2009-05-22 01:45:52pjenveysetnosy: + pjenvey
messages: + msg88175
2009-05-22 00:56:46rylescreate