PEP for fp.type()

Tim Cera timcera at
Tue Jan 15 22:13:50 EST 2002

"Skip Montanaro" <skip at> wrote 
> I see nothing wrong with a module like  I don't understand why
> this is best as a file method.  Your message didn't provide any motivation.

Your right, I didn't give a rational, just described the idea.

I can think of four reasons...

1) Duplication of function in imghdr, sndhdr, and mimetypes.  Both
imghdr and sndhdr do a similar thing to Unix 'file' and where
mimetypes looks at the filename extension.  All try to determine what
kind of file is out there. Also, what if it is a text file?  How do
you test with the standard modules?  Remember that the mimetypes
module does not sample the file.

2) The imghdr module is limited to testing for only 11 graphic
formats.  And in both cases when I should have been able to use it,
the format wasn't supported (ps and eps).  The sndhdr module seems a
little better off, covering 12 sound formats.

3) IANALL but it seems to make sense as a file method because it would
return a characteristic of the file.  Whether it makes sense as a file
method or an os method I don't think is the most important thing. 
Actually it would return information about a file similar to
os.stat().  Maybe os.filetype()?  Heck, maybe just extend to
support the mimetypes approach, but replace imghdr, sndhdr, and

4) Batteries Included!

take care
tim cera

More information about the Python-list mailing list