File name from file descriptor?

piet at piet at
Tue Jun 26 12:23:55 CEST 2001

>>>>> Carsten Gaebler <clpy at> (CG) writes:

CG> Carlos Ribeiro wrote:
>> functionality depend a lot on the OS being used. Could you please tell us
>> why do you *need* to make it work using file descriptors?

CG> The problem is this: I have a script that is called like

CG> ./ < somefile

CG> where somefile is a text file which may or may not be gzipped. To
CG> determine whether or not the data is gzipped I read in one byte via the
CG> gzip module. If that raises an exception I know the data is not gzipped.
CG> But I'd miss the first byte if it is gzipped. Yes, I could store this byte
CG> somewhere and then pass it around somehow, but ... you know? :-) So I'd
CG> like to open a second 'instance' of the file for reading but I only have
CG> sys.stdin's file descriptor.

If you are sure that stdin will be a real file you can use:,0)
Piet van Oostrum <piet at>
Private email: P.van.Oostrum at

More information about the Python-list mailing list