Laszlo Nagy wrote:
However, it won't work for temporary files. Temporary files are just
file-like objects, and their name is '<fdopen>'. I guess I could open a
temporary file with os.open, and then use os.dup, but that is low level
stuff. Then I have to use os.* methods, and the file object won't be
iterable. tempfile.NamedTempFile is not better, because it cannot be
reopened under Windows.

On POSIX OSes like Linux a temporary file *is* a real file. It just doesn't have a name on the file system anymore. The concept is called an anonymous file. Python creates the file in the tmp directory and unlinks the name. The file still needs resources on the file system but you can "see" it. The /proc/PID/fd/ directory will show the temporary files.

In order to copy the file handler you have to os.dup() the file descriptor (file_object.fileno()) and os.fdopen() it to get a file object. The Python documentation and the man pages dup(2), fileno(3) and fopen(3) will give you more information.

Christian

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to