<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>haojii &#187; python</title>
	<atom:link href="http://www.haojii.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haojii.com</link>
	<description>一个专注于技术的IT男</description>
	<lastBuildDate>Thu, 19 Apr 2012 07:58:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>如何用python生成文件的md5 checksum值</title>
		<link>http://www.haojii.com/2009/02/python-md5-checksum/</link>
		<comments>http://www.haojii.com/2009/02/python-md5-checksum/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 15:58:54 +0000</pubDate>
		<dc:creator>Jacky</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://www.haojii.com/?p=175</guid>
		<description><![CDATA[unix 下md5sum的python版本 pymd5sum.py 参考: http://en.wikipedia.org/wiki/Checksum http://en.wikipedia.org/wiki/MD5<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1" color="#FF0000" style="display: block !important; padding: 20px 0 5px !important;">其他文章：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2010%2F05%2Flearning-drive-5%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">学车日志(5)</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2011%2F08%2Ftip-download-a-bitcomet-only-torrent-file-with-thunder%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">技巧-用迅雷打开某些打不开的种子文件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2011%2F03%2Fjavascript-tools%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">记录最近用到的几个JavaScript文件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fqq-super-speed-upload-file%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">由QQ文件中转站超快速上传联想到</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>unix 下md5sum的python版本</p>
<p>pymd5sum.py</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/python
#encoding=utf-8
import io
import sys
import hashlib
import string

def printUsage():
	print ('''Usage: 1 pymd5sum.py &lt;filename&gt;''')

def main():
	if(sys.argv.__len__()==2):
		#print(sys.argv[1])

		m = hashlib.md5()
		file = io.FileIO(sys.argv[1],'r')
		bytes = file.read(1024)
		while(bytes != b''):
			m.update(bytes)
			bytes = file.read(1024)
		file.close()

		#md5value = &quot;&quot;
		md5value = m.hexdigest()
		print(md5value+&quot;\t&quot;+sys.argv[1])

		#dest = io.FileIO(sys.argv[1]+&quot;.CHECKSUM.md5&quot;,'w')
		#dest.write(md5value)
		#dest.close()

	else:
		printUsage()
main()
</pre>
<p>参考:<br />
<a href="http://en.wikipedia.org/wiki/Checksum">http://en.wikipedia.org/wiki/Checksum</a><br />
<a href="http://en.wikipedia.org/wiki/MD5">http://en.wikipedia.org/wiki/MD5</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1" color="#FF0000" style="display: block !important; padding: 20px 0 5px !important;">其他文章：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2010%2F05%2Flearning-drive-5%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">学车日志(5)</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2011%2F08%2Ftip-download-a-bitcomet-only-torrent-file-with-thunder%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">技巧-用迅雷打开某些打不开的种子文件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2011%2F03%2Fjavascript-tools%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">记录最近用到的几个JavaScript文件</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fqq-super-speed-upload-file%2F&from=http%3A%2F%2Fwww.haojii.com%2F2009%2F02%2Fpython-md5-checksum%2F">
                        <font size="-1" color="#667FFA" style="line-height: 1.65em; font-size: 12px !important;">由QQ文件中转站超快速上传联想到</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://www.haojii.com/2009/02/python-md5-checksum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

