Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86706
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <mail@timgolden.me.uk> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Windows': 0.02; 'binary': 0.07; 'computed': 0.09; 'converts': 0.09; 'data:': 0.09; 'mode:': 0.09; 'skip:2 30': 0.09; 'python': 0.11; 'def': 0.12; 'windows': 0.15; 'default)': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'hashlib': 0.16; 'md5': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'tjg': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'received:192.168.100': 0.24; 'skip:e 30': 0.24; 'code:': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'mode': 0.30; 'linux.': 0.31; 'file': 0.32; 'run': 0.32; 'text': 0.33; 'open': 0.33; 'linux': 0.33; 'but': 0.35; 'there': 0.35; 'should': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'break': 0.61; "you're": 0.61; 'different': 0.65; 'from:addr:mail': 0.83; 'amazed': 0.84; 'silently': 0.84 |
| Date | Mon, 02 Mar 2015 08:50:38 +0000 |
| From | Tim Golden <mail@timgolden.me.uk> |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Md5 is different in Windows and Linux |
| References | <CA+QVAb4D1JTnaQ5ZOaB51syt1_NePt+QeSHOxEmnhMjxr10BEQ@mail.gmail.com> |
| In-Reply-To | <CA+QVAb4D1JTnaQ5ZOaB51syt1_NePt+QeSHOxEmnhMjxr10BEQ@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| 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.18.1425286243.13471.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425286243 news.xs4all.nl 2945 [2001:888:2000:d::a6]:35326 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86706 |
Show key headers only | View raw
On 02/03/2015 06:19, Sarvagya Pant wrote:
> Hello, I am amazed that the md5 of a file given by python in windows is
> different than that of linux. Consider the following code:
>
> import hashlib
> def md5_for_file(f, block_size=2**20):
> md5 = hashlib.md5()
> while True:
> data = f.read(block_size)
> if not data:
> break
> md5.update(data)
> return md5.hexdigest()
>
> f = open("somefile.txt")
> print md5_for_file(f)
>
> When I run the program I get the checksum value:
> 2f9cc8da53ee89762a34702f745d2956
>
> But on this site http://onlinemd5.com/ and on linux it has value
> E10D4E3847713472F51BC606852712F1.
>
> Why is there difference in value of Checksum computed by python in
> windows and other system.?
Because you're opening the file in text mode (implicitly; that's the
default) which silently converts certain characters. If you open it in
binary mode:
f = open("somefile.txt", "rb")
then you should see the same result
TJG
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Md5 is different in Windows and Linux Tim Golden <mail@timgolden.me.uk> - 2015-03-02 08:50 +0000
csiph-web