Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60846 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-12-02 09:49 +1100 |
| Last post | 2013-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.
Re: Checking Common File Types Chris Angelico <rosuav@gmail.com> - 2013-12-02 09:49 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-12-02 09:49 +1100 |
| Subject | Re: 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
Back to top | Article view | comp.lang.python
csiph-web