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.

Author ned.deily
Recipients ned.deily, xiang.zhang
Date 2015-04-29.07:37:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430293064.77.0.234760121437.issue24073@psf.upfronthosting.co.za>
In-reply-to
Content
I think the issue here is that you are expecting the "mode" attribute of a file object (or io.* object in Py3) to reflect the "readable" and "writeable" access mode of the underlying file descriptor (for POSIX-like systems).  But, as noted in the documentation for the Py3 io.* objects and Py2 file object, their mode attributes reflect the "mode" given in the object constructor (for io.*) or the open() built-in (for Py2).  The default sys.stdin object will always be created as a "readable" file/io object from Python's perspective but that doesn't mean that any file descriptor to which the object might refer actually allows read access.  That may not be determined until your program does something that causes a call to the system runtime libraries that requires "read" access to the file, for example, sys.stdin.read() or, for Py2, os.fdopen(sys.stdin.fileno()).  (As documented, the Py3 os.fdopen is an alias of the open() built-in.)  If you need to know the access mode of a particular file descriptor, you can use fcntl.fcntl() F_GETFL function to examine the access mode of the fd.  Or you could just use try/except blocks to catch exceptions.

https://docs.python.org/3/library/os.html#os.open
https://docs.python.org/3/library/io.html#io.FileIO
https://docs.python.org/2/library/stdtypes.html#file.mode
https://docs.python.org/3/library/fcntl.html#fcntl.fcntl
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
History
Date User Action Args
2015-04-29 07:37:44ned.deilysetrecipients: + ned.deily, xiang.zhang
2015-04-29 07:37:44ned.deilysetmessageid: <1430293064.77.0.234760121437.issue24073@psf.upfronthosting.co.za>
2015-04-29 07:37:44ned.deilylinkissue24073 messages
2015-04-29 07:37:44ned.deilycreate