Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60846
| References | <DUB114-W56EEA08576BBC592BFF8029DEB0@phx.gbl> |
|---|---|
| Date | 2013-12-02 09:49 +1100 |
| Subject | Re: Checking Common File Types |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3449.1385938198.18130.python-list@python.org> (permalink) |
On Mon, Dec 2, 2013 at 5:27 AM, jade <jadec375@msn.com> wrote:
> file_sigs = {'\xFF\xD8\xFF':('JPEG','jpg'),
> '\x47\x49\x46':('GIF','gif')}
>
> file_sig = fh.read(4)
You're reading in four bytes, but your signatures are three bytes long. :)
After that, all you need to do is look up file_sig in the file_sigs
dictionary, and see if anything's there. Look at the Python docs for
the dict type; there's an easy way to do this.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Checking Common File Types Chris Angelico <rosuav@gmail.com> - 2013-12-02 09:49 +1100
csiph-web