Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60846
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'bytes,': 0.09; 'type;': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'dict': 0.16; 'dictionary,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'skip:{ 30': 0.16; 'subject:File': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'long.': 0.31; 'there.': 0.32; 'this.': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'that,': 0.38; 'easy': 0.60; "you're": 0.61; 'to:none': 0.92; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=R2r9liYAjponrcJtyv+v7tGeUyee51kaJaXs62bAd20=; b=dGJptSAcXfbv28D0BgbPEI36/TPIxUhta3YfWNl0FTRYzH8fWR6K/4yu2Rpd4wtBgH qKtwmRXQxng/EkQgpZAl5p69x/XdW6c5r5qS0D/xxB5YprmvLzfrCK6wOPrvBJd9osnx M/kn1bYVreAwOOFdLeArFKcgWRegNZ2U+8FQ2u0nz/GfGgF/+wrXJfwlWS86yXod4hDk qlO8xsQtkbqiRKR3RbFTsXyRnr/75XaSaBwXESN9F+v3uQywMar4+tQBvJmnF6L9xy8v wpJuP+bry+Czal90g1F1xZO8TlySwgyHs/RYOW0EbnA76xYIRFGvLx2UzTJydpv0n7Mj 29XQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.242.163 with SMTP id wr3mr27397627pbc.84.1385938194999; Sun, 01 Dec 2013 14:49:54 -0800 (PST) |
| In-Reply-To | <DUB114-W56EEA08576BBC592BFF8029DEB0@phx.gbl> |
| References | <DUB114-W56EEA08576BBC592BFF8029DEB0@phx.gbl> |
| Date | Mon, 2 Dec 2013 09:49:54 +1100 |
| Subject | Re: Checking Common File Types |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3449.1385938198.18130.python-list@python.org> (permalink) |
| Lines | 13 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1385938198 news.xs4all.nl 15974 [2001:888:2000:d::a6]:56442 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:60846 |
Show key headers only | View raw
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