[Python-Dev] IO module improvements (original) (raw)
Guido van Rossum guido at python.org
Sat Feb 6 00:51:51 CET 2010
- Previous message: [Python-Dev] IO module improvements
- Next message: [Python-Dev] IO module improvements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Feb 5, 2010 at 3:47 PM, Christian Heimes <lists at cheimes.de> wrote:
I had the idea to add a property that returns the file name based on the file descriptor. However there isn't a plain way to lookup the file based on the fd on POSIX OSes. fstat() returns only the inode and device. The combination of inode + device references 0 to n files due to anonymous files and hard links. On POSIX OSes with a /proc file systems it's possible to do a reverse lookup by (ab)using /proc/self/fd/, but that's a hack.
import os f = open("/etc/passwd") fd = f.fileno() os.readlink("/proc/self/fds/%i" % fd) '/etc/passwd' On Windows it's possible to get the file name from the handle with GetFileInformationByHandleEx(). This doesn't strike me as a feasible options ...
It's good to know about such options, but I really don't like to add such brittle APIs to the standard I/O objects. So, agreed, this is not feasible.
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] IO module improvements
- Next message: [Python-Dev] IO module improvements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]