Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60846 > unrolled thread

Re: Checking Common File Types

Started byChris Angelico <rosuav@gmail.com>
First post2013-12-02 09:49 +1100
Last post2013-12-02 09:49 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Checking Common File Types Chris Angelico <rosuav@gmail.com> - 2013-12-02 09:49 +1100

#60846 — Re: Checking Common File Types

FromChris Angelico <rosuav@gmail.com>
Date2013-12-02 09:49 +1100
SubjectRe: Checking Common File Types
Message-ID<mailman.3449.1385938198.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web