On Fri, Feb 5, 2010 at 3:47 PM, Christian Heimes <li...@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) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com