tempfile.mkstemp and os.fdopen

Nick Craig-Wood nick at craig-wood.com
Wed Aug 29 06:30:08 EDT 2007


Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
>  In message <Michael.J.Fromberger-8FC07C.15483428082007 at localhost>, Michael
>  J. Fromberger wrote:
> 
> > ... since os.fdopen() only has access to the file descriptor, it
> > does not have a convenient way to obtain the file's name.
> 
>  You can do this under Linux as follows:
> 
>      os.readlink("/proc/%d/fd/%d" % (os.getpid(), fileno))

A good idea!  You can write this slightly more succinctly as

  os.readlink("/proc/self/fd/%d" % fileno)

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list