testing the data-type of a stream

D

David Bear

I'm writing a filter and would like to be able to do what the Linux
'file' command does, i.e. look at a couple of bytes to see what kind of
data I'm dealing with, the branch based on the type.

I scanned the python library and couldn't find anything that seemed to
approximate this. I know I could do os.popen and call the file
command then parse the output, but would rather not if there is a
regular python module that can do it for me.

any recommendations?

--
David Bear
phone: 480-965-8257
fax: 480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
"Beware the IP portfolio, everyone will be suspect of trespassing"
 
H

Hans-Joachim Widmaier

David Bear said:
I'm writing a filter and would like to be able to do what the Linux
'file' command does, i.e. look at a couple of bytes to see what kind of
data I'm dealing with, the branch based on the type.
[...]
any recommendations?

You might want to take a look at 'magic'
http://www.demonseed.net/~jp/code/magic.py> Reading a few bytes from a
file and passing them on is considered trivial and left as an
exercise. ;-)

Hans-J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top