﻿<?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>奋斗足迹&#124;崔玉松 &#187; Programming</title>
	<atom:link href="http://fendou.org/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://fendou.org</link>
	<description>为家人，为自己，为生活~~</description>
	<lastBuildDate>Fri, 24 Feb 2012 15:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Python Web.py框架实现的简易REST服务原型</title>
		<link>http://fendou.org/2011/02/15/web-py-restful-service/</link>
		<comments>http://fendou.org/2011/02/15/web-py-restful-service/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 02:04:10 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=807</guid>
		<description><![CDATA[Web.py是python web框架中比较轻量级的，只实现了一些必要的组件，个人比较喜欢这样的框架，虽然功能并不完整，在我所做过的项目中，实际上并没有一款框架能够适合，或许是因为电子商务领域特殊性，也或许是因为公司太大，依赖的东西更多，直接导致了任何一款框架拿过来，写着写着就需要动框架本身的东西，不动它就实现不了业务，由于这个原因，我更偏爱简洁、轻量的框架，修改起来方便，至于组件，既然别的框架已经实现了，拿来改改就能用上了。当然，如果只是普通的CMS之类的开发，没有很多复杂的业务，我更推荐各位使用功能丰富，大而全的框架，比如Rails，比如Django，或者PHP里的很多类似的框架，可以省不少时间，至少分页类不用自己搞了。在复杂的项目中，这些时间是不能省的，否则会导致日后业务的灾难性后果或者需要更多的时间去修改框架。 废话多了，关于web.py可以参考官方网站，中文的入门文档也很全，写起来非常的简单，基本上不用改什么就可以迁移到Google App Engine上。下面上代码： import web import json from mimerender import mimerender &#160; render_xml = lambda message: '&#60;message&#62;%s&#60;/message&#62;'%message render_json = lambda **args: json.dumps&#40;args&#41; render_html = lambda message: '&#60;html&#62;&#60;body&#62;%s&#60;/body&#62;&#60;/html&#62;'%message render_txt = lambda message: message &#160; urls = &#40; '/(.*)', 'greet' &#41; app = web.application&#40;urls, globals&#40;&#41;&#41; &#160; class greet: @mimerender&#40; default = 'html', html = render_html,...  <a href="http://fendou.org/2011/02/15/web-py-restful-service/" class="more-link" title="Read Python Web.py框架实现的简易REST服务原型">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python中给urllib2设置超时时间" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python中给urllib2设置超时时间</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python和其他语言数据类型比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python和其他语言数据类型比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>Web.py是python web框架中比较轻量级的，只实现了一些必要的组件，个人比较喜欢这样的框架，虽然功能并不完整，在我所做过的项目中，实际上并没有一款框架能够适合，或许是因为电子商务领域特殊性，也或许是因为公司太大，依赖的东西更多，直接导致了任何一款框架拿过来，写着写着就需要动框架本身的东西，不动它就实现不了业务，由于这个原因，我更偏爱简洁、轻量的框架，修改起来方便，至于组件，既然别的框架已经实现了，拿来改改就能用上了。当然，如果只是普通的CMS之类的开发，没有很多复杂的业务，我更推荐各位使用功能丰富，大而全的框架，比如Rails，比如Django，或者PHP里的很多类似的框架，可以省不少时间，至少分页类不用自己搞了。在复杂的项目中，这些时间是不能省的，否则会导致日后业务的灾难性后果或者需要更多的时间去修改框架。<br />
废话多了，关于<a href="http://webpy.org/">web.py</a>可以参考官方网站，中文的入门文档也很全，写起来非常的简单，基本上不用改什么就可以迁移到Google App Engine上。下面上代码：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> web
<span style="color: #ff7700;font-weight:bold;">import</span> json
<span style="color: #ff7700;font-weight:bold;">from</span> mimerender <span style="color: #ff7700;font-weight:bold;">import</span> mimerender
&nbsp;
render_xml = <span style="color: #ff7700;font-weight:bold;">lambda</span> message: <span style="color: #483d8b;">'&lt;message&gt;%s&lt;/message&gt;'</span><span style="color: #66cc66;">%</span>message
render_json = <span style="color: #ff7700;font-weight:bold;">lambda</span> <span style="color: #66cc66;">**</span>args: json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span>
render_html = <span style="color: #ff7700;font-weight:bold;">lambda</span> message: <span style="color: #483d8b;">'&lt;html&gt;&lt;body&gt;%s&lt;/body&gt;&lt;/html&gt;'</span><span style="color: #66cc66;">%</span>message
render_txt = <span style="color: #ff7700;font-weight:bold;">lambda</span> message: message
&nbsp;
urls = <span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">'/(.*)'</span>, <span style="color: #483d8b;">'greet'</span>
<span style="color: black;">&#41;</span>
app = web.<span style="color: black;">application</span><span style="color: black;">&#40;</span>urls, <span style="color: #008000;">globals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> greet:
    @mimerender<span style="color: black;">&#40;</span>
        default = <span style="color: #483d8b;">'html'</span>,
        html = render_html,
        <span style="color: #dc143c;">xml</span>  = render_xml,
        json = render_json,
        txt  = render_txt
    <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> name:
            name = <span style="color: #483d8b;">'world'</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'message'</span>: <span style="color: #483d8b;">'Hello, '</span> + name + <span style="color: #483d8b;">'!'</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    app.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>最后使用CURL加模拟的header参数的输出是这样的：<br />
<img src="http://pic.yupoo.com/cuimuxi_v/AQJED8nr/I9w6E.jpg" alt="web.py output" /></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python中给urllib2设置超时时间" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python中给urllib2设置超时时间</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python和其他语言数据类型比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python和其他语言数据类型比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F15%2Fweb-py-restful-service%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2011/02/15/web-py-restful-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XAMPP集成环境中安装PHPUnit</title>
		<link>http://fendou.org/2011/02/10/xampp-phpunit-install/</link>
		<comments>http://fendou.org/2011/02/10/xampp-phpunit-install/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 06:43:35 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[常识]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=804</guid>
		<description><![CDATA[PHPUnit是一个轻量级的PHP测试框架。它是在PHP5下面对JUnit3系列版本的完整移植，是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计)。单元测试是几个现代敏捷开发方法的基础，使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ，并且可以与phing集成来自动测试，最后它还可以和Selenium整合来完成大型的自动化集成测试。 Windows平台LAMP环境XAMPP 1.7.3下如何安装PHPUnit呢？ 首先，以管理员身份运行cmd，使用pear添加phpunit频道： D:\xampp\php>pear channel-discover pear.phpunit.de Channel “pear.phpunit.de” is already initialized 频道添加好，尝试安装PHPUnit： D:\xampp\php>pear install phpunit/PHPUnit Unknown remote channel: pear.symfony-project.com Unknown remote channel: pear.symfony-project.com Unknown remote channel: components.ez.no Unknown remote channel: components.ez.no phpunit/PHPUnit requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0 phpunit/PHPUnit requires package “channel://pear.symfony-project.com/YAML” (version >= 1.0.2) phpunit/PHPUnit can optionally...  <a href="http://fendou.org/2011/02/10/xampp-phpunit-install/" class="more-link" title="Read XAMPP集成环境中安装PHPUnit">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2009%2F06%2F07%2Fscaling-php%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP是可扩展的语言</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%2Ffendou.org%2F2007%2F12%2F05%2Fvisibility-in-php%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Visibility in PHP</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%2Ffendou.org%2F2008%2F05%2F12%2Fphp6%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 6 的新特性</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%2Ffendou.org%2F2007%2F11%2F30%2Fwhy-php-hacks%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Why PHP Hacks?</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%2Ffendou.org%2F2007%2F11%2F02%2F%25E5%2588%259D%25E5%25AD%25A6php%25E7%259A%258418%25E4%25B8%25AA%25E5%259F%25BA%25E7%25A1%2580%25E4%25BE%258B%25E7%25A8%258B%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">初学PHP的18个基础例程</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>PHPUnit是一个轻量级的PHP测试框架。它是在PHP5下面对JUnit3系列版本的完整移植，是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计)。单元测试是几个现代敏捷开发方法的基础，使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ，并且可以与phing集成来自动测试，最后它还可以和Selenium整合来完成大型的自动化集成测试。</p>
<p>Windows平台LAMP环境XAMPP 1.7.3下如何安装PHPUnit呢？</p>
<p>首先，以管理员身份运行cmd，使用pear添加phpunit频道：</p>
<p>D:\xampp\php>pear channel-discover pear.phpunit.de<br />
Channel “pear.phpunit.de” is already initialized</p>
<p>频道添加好，尝试安装PHPUnit：</p>
<p>D:\xampp\php>pear install phpunit/PHPUnit<br />
Unknown remote channel: pear.symfony-project.com<br />
Unknown remote channel: pear.symfony-project.com<br />
Unknown remote channel: components.ez.no<br />
Unknown remote channel: components.ez.no<br />
phpunit/PHPUnit requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHPUnit requires package “channel://pear.symfony-project.com/YAML” (version >= 1.0.2)<br />
phpunit/PHPUnit can optionally use PHP extension “dbus”<br />
phpunit/DbUnit requires PEAR Installer (version >= 1.9.1), installed version is1.9.0<br />
phpunit/DbUnit requires package “channel://pear.symfony-project.com/YAML” (version >= 1.0.2)<br />
phpunit/File_Iterator requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHP_CodeCoverage requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHP_CodeCoverage requires package “channel://components.ez.no/ConsoleTools” (version >= 1.6)<br />
phpunit/PHP_CodeCoverage requires package “phpunit/File_Iterator” (version >= 1.2.2)<br />
phpunit/PHP_CodeCoverage can optionally use PHP extension “xdebug” (version >= 2.0.5)<br />
phpunit/PHPUnit_MockObject requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHPUnit_Selenium requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHP_TokenStream requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0<br />
phpunit/PHP_TokenStream requires package “channel://components.ez.no/ConsoleTools” (version >= 1.6)<br />
No valid packages found<br />
install failed</p>
<p>从提示看出，需要安装PEAR 1.9.1，而当前PEAR是1.9.0，那就要先升级PEAR版本。</p>
<p>pear list-upgrades可以列出当前可用的更新，<br />
D:\xampp\php>pear.bat list-upgrades<br />
WARNING: channel “pear.php.net” has updated its protocols, use “pear channel-update pear.php.net” to<br />
update</p>
<p>D:\xampp\php>pear channel-update pear.php.net<br />
Updating channel “pear.php.net”<br />
Update of Channel “pear.php.net” succeeded</p>
<p>D:\xampp\php>pear.bat list-upgrades<br />
PEAR.PHP.NET AVAILABLE UPGRADES (STABLE):<br />
=========================================<br />
CHANNEL     PACKAGE          LOCAL           REMOTE          SIZE<br />
pear.php.net Archive_Tar     1.3.3 (stable)  1.3.7 (stable)  17.2kB<br />
pear.php.net Console_Getargs 1.3.4 (stable)  1.3.5 (stable)  17.8kB<br />
pear.php.net Mail            1.1.14 (stable) 1.2.0 (stable)  23kB<br />
pear.php.net Mail_Mime       1.5.2 (stable)  1.8.1 (stable)  31kB<br />
pear.php.net Mail_mimeDecode 1.5.1 (stable)  1.5.5 (stable)  11.4kB<br />
pear.php.net Net_SMTP        1.3.4 (stable)  1.4.4 (stable)  12.1kB<br />
pear.php.net Net_Socket      1.0.9 (stable)  1.0.10 (stable) 5.3kB<br />
pear.php.net PEAR            1.9.0 (stable)  1.9.1 (stable)  287kB<br />
pear.php.net Structures_Graph 1.0.3 (stable) 1.0.4 (stable)  30kB<br />
Channel pear.phpunit.de: No upgrades available<br />
ZEND.GOOGLECODE.COM/SVN AVAILABLE UPGRADES (STABLE):<br />
====================================================<br />
CHANNEL                PACKAGE LOCAL          REMOTE          SIZE<br />
zend.googlecode.com/svn zend   1.9.6 (stable) 1.11.1 (stable)   -</p>
<p>更新所有可用更新：<br />
D:\xampp\php>pear upgrade-all<br />
Will upgrade channel://pear.php.net/archive_tar<br />
Will upgrade channel://pear.php.net/console_getargs<br />
Will upgrade channel://pear.php.net/mail<br />
Will upgrade channel://pear.php.net/mail_mime<br />
Will upgrade channel://pear.php.net/mail_mimedecode<br />
Will upgrade channel://pear.php.net/net_smtp<br />
Will upgrade channel://pear.php.net/net_socket<br />
Will upgrade channel://pear.php.net/pear<br />
Will upgrade channel://pear.php.net/structures_graph<br />
Will upgrade channel://zend.googlecode.com/svn/zend<br />
Did not download optional dependencies: pear/Auth_SASL, use &#8211;alldeps to download automatically<br />
pear/Net_SMTP can optionally use package “pear/Auth_SASL”<br />
downloading Archive_Tar-1.3.7.tgz &#8230;<br />
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)<br />
&#8230;&#8230;done: 17,610 bytes<br />
downloading Console_Getargs-1.3.5.tgz &#8230;<br />
Starting to download Console_Getargs-1.3.5.tgz (18,207 bytes)<br />
&#8230;done: 18,207 bytes<br />
downloading Mail-1.2.0.tgz &#8230;<br />
Starting to download Mail-1.2.0.tgz (23,214 bytes)<br />
&#8230;done: 23,214 bytes<br />
downloading Mail_Mime-1.8.1.tgz &#8230;<br />
Starting to download Mail_Mime-1.8.1.tgz (31,530 bytes)<br />
&#8230;done: 31,530 bytes<br />
downloading Mail_mimeDecode-1.5.5.tgz &#8230;<br />
Starting to download Mail_mimeDecode-1.5.5.tgz (11,554 bytes)<br />
&#8230;done: 11,554 bytes<br />
downloading Net_SMTP-1.4.4.tgz &#8230;<br />
Starting to download Net_SMTP-1.4.4.tgz (12,264 bytes)<br />
&#8230;done: 12,264 bytes<br />
downloading Net_Socket-1.0.10.tgz &#8230;<br />
Starting to download Net_Socket-1.0.10.tgz (5,429 bytes)<br />
&#8230;done: 5,429 bytes<br />
downloading PEAR-1.9.1.tgz &#8230;<br />
Starting to download PEAR-1.9.1.tgz (293,587 bytes)<br />
&#8230;done: 293,587 bytes<br />
downloading Structures_Graph-1.0.4.tgz &#8230;<br />
Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes)<br />
&#8230;done: 30,318 bytes<br />
downloading Zend-1.11.1.tgz &#8230;<br />
Starting to download Zend-1.11.1.tgz (3,638,888 bytes)<br />
&#8230;done: 3,638,888 bytes<br />
upgrade-all ok: channel://pear.php.net/Archive_Tar-1.3.7<br />
upgrade-all ok: channel://pear.php.net/Console_Getargs-1.3.5<br />
upgrade-all ok: channel://pear.php.net/Mail-1.2.0<br />
upgrade-all ok: channel://pear.php.net/Mail_Mime-1.8.1<br />
upgrade-all ok: channel://pear.php.net/Net_Socket-1.0.10<br />
upgrade-all ok: channel://pear.php.net/Structures_Graph-1.0.4<br />
upgrade-all ok: channel://zend.googlecode.com/svn/Zend-1.11.1<br />
upgrade-all ok: channel://pear.php.net/Mail_mimeDecode-1.5.5<br />
upgrade-all ok: channel://pear.php.net/Net_SMTP-1.4.4<br />
upgrade-all ok: channel://pear.php.net/PEAR-1.9.1<br />
PEAR: Optional feature webinstaller available (PEAR&#8217;s web-based installer)<br />
PEAR: Optional feature gtkinstaller available (PEAR&#8217;s PHP-GTK-based installer)<br />
PEAR: Optional feature gtk2installer available (PEAR&#8217;s PHP-GTK2-based installer)<br />
PEAR: To install optional features use “pear install pear/PEAR#featurename”</p>
<p>更新成功后，PEAR已经是最新版了，<br />
pear.symfony-project.com和components.ez.no两个频道也要添加一下：</p>
<p>D:\xampp\php>pear channel-discover pear.symfony-project.com<br />
Adding Channel “pear.symfony-project.com” succeeded<br />
Discovery of channel “pear.symfony-project.com” succeeded</p>
<p>D:\xampp\php>pear channel-discover components.ez.no<br />
Adding Channel “components.ez.no” succeeded<br />
Discovery of channel “components.ez.no” succeeded</p>
<p>再次尝试安装PHPUnit：</p>
<p>D:\xampp\php>pear install phpunit/PHPUnit<br />
phpunit/PHPUnit can optionally use PHP extension “dbus”<br />
phpunit/PHP_CodeCoverage can optionally use PHP extension “xdebug” (version >= 2.0.5)<br />
downloading PHPUnit-3.5.5.tgz &#8230;<br />
Starting to download PHPUnit-3.5.5.tgz (116,148 bytes)<br />
&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..done: 116,148 bytes<br />
downloading DbUnit-1.0.0.tgz &#8230;<br />
Starting to download DbUnit-1.0.0.tgz (38,183 bytes)<br />
&#8230;done: 38,183 bytes<br />
downloading PHP_CodeCoverage-1.0.2.tgz &#8230;<br />
Starting to download PHP_CodeCoverage-1.0.2.tgz (109,280 bytes)<br />
&#8230;done: 109,280 bytes<br />
downloading YAML-1.0.4.tgz &#8230;<br />
Starting to download YAML-1.0.4.tgz (9,919 bytes)<br />
&#8230;done: 9,919 bytes<br />
downloading ConsoleTools-1.6.1.tgz &#8230;<br />
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)<br />
&#8230;done: 869,994 bytes<br />
downloading PHP_TokenStream-1.0.1.tgz &#8230;<br />
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)<br />
&#8230;done: 7,250 bytes<br />
downloading Base-1.8.tgz &#8230;<br />
Starting to download Base-1.8.tgz (236,357 bytes)<br />
&#8230;done: 236,357 bytes<br />
install ok: channel://pear.symfony-project.com/YAML-1.0.4<br />
install ok: channel://components.ez.no/Base-1.8<br />
install ok: channel://pear.phpunit.de/DbUnit-1.0.0<br />
install ok: channel://components.ez.no/ConsoleTools-1.6.1<br />
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1<br />
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.2<br />
install ok: channel://pear.phpunit.de/PHPUnit-3.5.5</p>
<p>PHPUnit安装成功！！！</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2009%2F06%2F07%2Fscaling-php%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP是可扩展的语言</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%2Ffendou.org%2F2007%2F12%2F05%2Fvisibility-in-php%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Visibility in PHP</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%2Ffendou.org%2F2008%2F05%2F12%2Fphp6%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 6 的新特性</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%2Ffendou.org%2F2007%2F11%2F30%2Fwhy-php-hacks%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Why PHP Hacks?</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%2Ffendou.org%2F2007%2F11%2F02%2F%25E5%2588%259D%25E5%25AD%25A6php%25E7%259A%258418%25E4%25B8%25AA%25E5%259F%25BA%25E7%25A1%2580%25E4%25BE%258B%25E7%25A8%258B%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F02%2F10%2Fxampp-phpunit-install%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">初学PHP的18个基础例程</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://fendou.org/2011/02/10/xampp-phpunit-install/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python PIL 生成带阴影的缩略图</title>
		<link>http://fendou.org/2011/01/31/python-pil-shadow-thumb/</link>
		<comments>http://fendou.org/2011/01/31/python-pil-shadow-thumb/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 07:10:58 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=802</guid>
		<description><![CDATA[iimport sys from PIL import Image, ImageFilter &#160; def dropShadow&#40; image, offset=&#40;5,5&#41;, background=0xffffff, shadow=0x444444, border=8, iterations=3&#41;: &#34;&#34;&#34; 把图像放在一个作了高斯模糊的背景上 &#160; image - 要放在背景上的原始图像 offset - 阴影相对图像的偏移，用(x,y)表示，可以为正数或者负数 background - 背景色 shadow - 阴影色 border - 图像边框，必须足够用来制作阴影模糊 iterations - 过滤器处理次数，次数越多越模糊，当然处理过程也越慢 &#34;&#34;&#34; &#160; # 创建背景块 totalWidth = image.size&#91;0&#93; + abs&#40;offset&#91;0&#93;&#41; + 2*border totalHeight = image.size&#91;1&#93; + abs&#40;offset&#91;1&#93;&#41; + 2*border...  <a href="http://fendou.org/2011/01/31/python-pil-shadow-thumb/" class="more-link" title="Read Python PIL 生成带阴影的缩略图">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">python非贪婪、多行匹配正则表达式例子</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%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python和其他语言数据类型比较</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%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows平台安装Python2.6 和 MySQL-Python</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%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python Queue 的多线程(multi thread)死锁问题</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%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">超级简单Python Socket Server一例</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[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">iimport <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> PIL <span style="color: #ff7700;font-weight:bold;">import</span> Image, ImageFilter
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> dropShadow<span style="color: black;">&#40;</span> image, offset=<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>, background=0xffffff,
        shadow=0x444444, border=<span style="color: #ff4500;">8</span>, iterations=<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    把图像放在一个作了高斯模糊的背景上
&nbsp;
    image       - 要放在背景上的原始图像
    offset      - 阴影相对图像的偏移，用(x,y)表示，可以为正数或者负数
    background - 背景色
    shadow      - 阴影色
    border      - 图像边框，必须足够用来制作阴影模糊
    iterations - 过滤器处理次数，次数越多越模糊，当然处理过程也越慢
    &quot;&quot;&quot;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># 创建背景块</span>
    totalWidth = image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">abs</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">2</span><span style="color: #66cc66;">*</span>border
    totalHeight = image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">abs</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">2</span><span style="color: #66cc66;">*</span>border
    back = Image.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>image.<span style="color: black;">mode</span>, <span style="color: black;">&#40;</span>totalWidth, totalHeight<span style="color: black;">&#41;</span>, background<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># 放置阴影块，考虑图像偏移</span>
    shadowLeft = border + <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
    shadowTop = border + <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
    back.<span style="color: black;">paste</span><span style="color: black;">&#40;</span>shadow, <span style="color: black;">&#91;</span>shadowLeft, shadowTop, shadowLeft + image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,
        shadowTop + image.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># 处理阴影的边缘模糊</span>
    n = <span style="color: #ff4500;">0</span>
    <span style="color: #ff7700;font-weight:bold;">while</span> n <span style="color: #66cc66;">&amp;</span>lt<span style="color: #66cc66;">;</span> iterations:
        back = back.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>ImageFilter.<span style="color: black;">BLUR</span><span style="color: black;">&#41;</span>
        n += <span style="color: #ff4500;">1</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># 把图像粘贴到背景上</span>
    imageLeft = border - <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
    imageTop = border - <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>offset<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
    back.<span style="color: black;">paste</span><span style="color: black;">&#40;</span>image, <span style="color: black;">&#40;</span>imageLeft, imageTop<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> back
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    pic=<span style="color: #483d8b;">&quot;BCEB4D33FC86DC647461670FFC23D260.jpg&quot;</span>
    image = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>pic<span style="color: black;">&#41;</span>
    image.<span style="color: black;">thumbnail</span><span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">300</span>,<span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>, Image.<span style="color: black;">ANTIALIAS</span><span style="color: black;">&#41;</span>
&nbsp;
    dropShadow<span style="color: black;">&#40;</span>image<span style="color: black;">&#41;</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    dropShadow<span style="color: black;">&#40;</span>image, background=0xeeeeee,
                  shadow=0x444444, offset=<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>生成前的原图：<br />
<img src="http://pic.yupoo.com/cuimuxi_v/AOu9YruG/NCl0D.jpg" alt="生成前的原图" /><br />
生成后的带阴影图：<br />
<img src="http://pic.yupoo.com/cuimuxi_v/AOu9YjyP/pGth5.jpg" alt="生成后带阴影图" /></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">python非贪婪、多行匹配正则表达式例子</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%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python和其他语言数据类型比较</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%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows平台安装Python2.6 和 MySQL-Python</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%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python Queue 的多线程(multi thread)死锁问题</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%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">超级简单Python Socket Server一例</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://fendou.org/2011/01/31/python-pil-shadow-thumb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python 批量生成缩略图</title>
		<link>http://fendou.org/2011/01/31/python-thumb-image/</link>
		<comments>http://fendou.org/2011/01/31/python-thumb-image/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 02:14:33 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=796</guid>
		<description><![CDATA[首先上代码 # coding=utf-8 &#160; import os import Image &#160; # 字义缩放百分比 rate = 40 &#160; # 缩略图命名，在后面加上 resizedAddone = '_resized' &#160; # 支持格式 suportFormat = &#91;'bmp', 'gif', 'jpg', 'png'&#93; &#160; def process&#40;arg, dirs, files&#41;: for file in files: fileExt = os.path.splitext&#40;file&#41;&#91;1&#93;.lower&#40;&#41;&#91;1:&#93; if fileExt in suportFormat: img = Image.open&#40;file&#41; img.thumbnail&#40;&#40;img.size&#91;0&#93; * rate / 100, img.size&#91;1&#93; *...  <a href="http://fendou.org/2011/01/31/python-thumb-image/" class="more-link" title="Read Python 批量生成缩略图">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python中给urllib2设置超时时间" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python中给urllib2设置超时时间</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>首先上代码</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># coding=utf-8</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Image
&nbsp;
<span style="color: #808080; font-style: italic;"># 字义缩放百分比</span>
rate = <span style="color: #ff4500;">40</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 缩略图命名，在后面加上</span>
resizedAddone = <span style="color: #483d8b;">'_resized'</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 支持格式</span>
suportFormat = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'bmp'</span>, <span style="color: #483d8b;">'gif'</span>, <span style="color: #483d8b;">'jpg'</span>, <span style="color: #483d8b;">'png'</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> process<span style="color: black;">&#40;</span>arg, dirs, files<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> files:
        fileExt = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">splitext</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> fileExt <span style="color: #ff7700;font-weight:bold;">in</span> suportFormat:
            img = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span>
            img.<span style="color: black;">thumbnail</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>img.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">*</span> rate / <span style="color: #ff4500;">100</span>,
                                img.<span style="color: black;">size</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">*</span> rate / <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            img.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span>  \
                               + resizedAddone    \
                               + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>rate<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'.'</span> + fileExt<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span>, process, <span style="color: #483d8b;">'123'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>要运行此段代码需要安装<a href="http://www.pythonware.com/products/pil/">PIL</a>库，这是一个比较优秀的Python 图像处理库，使用的普及率类似PHP中的GD库，比较成熟和稳定，如果你需要更高的性能，<a href="http://www.imagemagick.org/script/api.php">image magick</a> 是个相当不错的选择，<a href="http://www.imagemagick.org/script/api.php">image magick</a> 的PHP扩展仍然有相当多的Bug，一般应用应该问题不大，至少在我的项目中应用还没出现过问题，我只是简单的应用到了缩略图的功能，仍然建议以命令行的形式调用，python 版本的还没试用过，从各方的使用反馈来看，似乎比PHP版本的口碑更好。</p>
<p>上面的代码是按照比例做缩略图，只需把源码放到你的图片目录下，然后运行就能批量生成缩略图了，如果你是需要固定尺寸的缩略图，只是需要 img.thumbnail()传递一个固定尺寸的tuple就好了，类似这样：img.thumbnail((120,100))，更多详细请查看<a href="http://www.pythonware.com/library/pil/handbook/index.htm">PIL文档</a>，不过这个<a href="http://www.pythonware.com/library/pil/handbook/index.htm">文档</a>相当的长，PDF版本有77页，非常的详细，当然也是因为PIL功能相当的完备和强大</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python中给urllib2设置超时时间" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python中给urllib2设置超时时间</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2011/01/31/python-thumb-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Httpsqs Python Client</title>
		<link>http://fendou.org/2011/01/25/httpsqs-python-client/</link>
		<comments>http://fendou.org/2011/01/25/httpsqs-python-client/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 03:51:05 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=788</guid>
		<description><![CDATA[Httpsqs 是张宴基于Tokyo Cabinet做的一个队列服务 前些日子项目中需要一个队列服务，因为配合Gearman做分发服务，因为之前的一些经历和教训，没有采用PHP作为脚本语言，当然并不是说PHP不行，只是懒得去折腾一些莫名其妙的问题，转而采用在更稳定更省心的Python做开发，之前其他的项目组中有使用Httpsqs的经历，我的leader强烈建议我使用这个，其实我更倾向memcacheQ 或者redis，Httpsqs没有Python版本的client，顺手写了一个，地址如下: http://code.google.com/p/httpsqs/source/browse/#svn%2Ftrunk%2Fclient%2Fpython 这个玩意是能正常的跑在我的项目中，不能保证能完全满足你的需求，如果你有任何建议或者意见，也欢迎联系我，特别附加一句：本人对此代码所带来的一切悲剧或者喜剧不承担任何责任，请慎重使用！ 贴一段关于httpsqs的介绍，怕有些人不知道，知道的请忽略。 TTPSQS（HTTP Simple Queue Service）是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务，使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。 　　项目网址：http://code.google.com/p/httpsqs/ 　　使用文档：http://blog.s135.com/httpsqs/ 　　使用环境：Linux（同时支持32位、64位操作系统，推荐使用64位操作系统） 　　软件作者：张宴 　　队列（Queue）又称先进先出表（First In First Out），即先进入队列的元素，先从队列中取出。加入元素的一头叫“队头”，取出元素的一头叫“队尾”。利用消息队列可以很好地异步处理数据传送和存储，当你频繁地向数据库中插入数据、频繁地向搜索引擎提交数据，就可采取消息队列来异步插入。另外，还可以将较慢的处理逻辑、有并发数量限制的处理逻辑，通过消息队列放在后台处理，例如FLV视频转换、发送手机短信、发送电子邮件等。 　　HTTPSQS 具有以下特征： 　　● 非常简单，基于 HTTP GET/POST 协议。PHP、Java、Perl、Shell、Python、Ruby等支持HTTP协议的编程语言均可调用。 　　● 非常快速，入队列、出队列速度超过10000次/秒。 　　● 高并发，支持上万的并发连接，C10K不成问题。 　　● 支持多队列。 　　● 单个队列支持的最大队列数量高达10亿条。 　　● 低内存消耗，海量数据存储，存储几十GB的数据只需不到100MB的物理内存缓冲区。 　　● 可以在不停止服务的情况下便捷地修改单个队列的最大队列数量。 　　● 可以实时查看队列状态（入队列位置、出队列位置、未读队列数量、最大队列数量）。 　　● 可以查看指定队列ID（队列点）的内容，包括未出、已出的队列内容。 　　● 查看队列内容时，支持多字符集编码。 　　●...  <a href="http://fendou.org/2011/01/25/httpsqs-python-client/" class="more-link" title="Read Httpsqs Python Client">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python非贪婪、多行匹配正则表达式例子" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python非贪婪、多行匹配正则表达式例子</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python Queue 的多线程(multi thread)死锁问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python Queue 的多线程(multi thread)死锁问题</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python 批量生成缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python 批量生成缩略图</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>Httpsqs 是<a href="http://blog.s135.com">张宴</a>基于Tokyo Cabinet做的一个队列服务<br />
前些日子项目中需要一个队列服务，因为配合Gearman做分发服务，因为之前的一些经历和教训，没有采用PHP作为脚本语言，当然并不是说PHP不行，只是懒得去折腾一些莫名其妙的问题，转而采用在更稳定更省心的Python做开发，之前其他的项目组中有使用Httpsqs的经历，我的leader强烈建议我使用这个，其实我更倾向memcacheQ 或者redis，Httpsqs没有Python版本的client，顺手写了一个，地址如下:<br />
<a href="http://code.google.com/p/httpsqs/source/browse/#svn%2Ftrunk%2Fclient%2Fpython">http://code.google.com/p/httpsqs/source/browse/#svn%2Ftrunk%2Fclient%2Fpython</a></p>
<p>这个玩意是能正常的跑在我的项目中，不能保证能完全满足你的需求，如果你有任何建议或者意见，也欢迎<a href="http://fendou.org/contact/">联系我</a>，特别附加一句：本人对此代码所带来的一切悲剧或者喜剧不承担任何责任，请慎重使用！</p>
<p>贴一段关于httpsqs的介绍，怕有些人不知道，知道的请忽略。</p>
<blockquote>
<p>TTPSQS（HTTP Simple Queue Service）是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务，使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。</p>
<p>　　项目网址：http://code.google.com/p/httpsqs/<br />
　　使用文档：http://blog.s135.com/httpsqs/<br />
　　使用环境：Linux（同时支持32位、64位操作系统，推荐使用64位操作系统）<br />
　　软件作者：张宴</p>
<p>　　队列（Queue）又称先进先出表（First In First Out），即先进入队列的元素，先从队列中取出。加入元素的一头叫“队头”，取出元素的一头叫“队尾”。利用消息队列可以很好地异步处理数据传送和存储，当你频繁地向数据库中插入数据、频繁地向搜索引擎提交数据，就可采取消息队列来异步插入。另外，还可以将较慢的处理逻辑、有并发数量限制的处理逻辑，通过消息队列放在后台处理，例如FLV视频转换、发送手机短信、发送电子邮件等。</p>
<p>　　HTTPSQS 具有以下特征：</p>
<p>　　● 非常简单，基于 HTTP GET/POST 协议。PHP、Java、Perl、Shell、Python、Ruby等支持HTTP协议的编程语言均可调用。<br />
　　● 非常快速，入队列、出队列速度超过10000次/秒。<br />
　　● 高并发，支持上万的并发连接，C10K不成问题。<br />
　　● 支持多队列。<br />
　　● 单个队列支持的最大队列数量高达10亿条。<br />
　　● 低内存消耗，海量数据存储，存储几十GB的数据只需不到100MB的物理内存缓冲区。<br />
　　● 可以在不停止服务的情况下便捷地修改单个队列的最大队列数量。<br />
　　● 可以实时查看队列状态（入队列位置、出队列位置、未读队列数量、最大队列数量）。<br />
　　● 可以查看指定队列ID（队列点）的内容，包括未出、已出的队列内容。<br />
　　● 查看队列内容时，支持多字符集编码。<br />
　　● 源代码不超过800行，适合二次开发。
</p></blockquote>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python非贪婪、多行匹配正则表达式例子" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python非贪婪、多行匹配正则表达式例子</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python Queue 的多线程(multi thread)死锁问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python Queue 的多线程(multi thread)死锁问题</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python 批量生成缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python 批量生成缩略图</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2011/01/25/httpsqs-python-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Queue 的多线程(multi thread)死锁问题</title>
		<link>http://fendou.org/2011/01/25/python-queue-lock/</link>
		<comments>http://fendou.org/2011/01/25/python-queue-lock/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 01:51:22 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=782</guid>
		<description><![CDATA[废话不多说，先上代码： #encoding=utf-8 import threading import random import time from Queue import Queue import mutex &#160; class Producer&#40;threading.Thread&#41;: &#160; def __init__&#40;self, threadname, queue, lock&#41;: threading.Thread.__init__&#40;self, name = threadname&#41; self.sharedata = queue self.lock = lock &#160; def run&#40;self&#41;: for i in range&#40;20&#41;: #---------------- self.lock.acquire&#40;&#41; print self.getName&#40;&#41;,'&#60;&#60; ',i self.lock.release&#40;&#41; #---------------- self.sharedata.put&#40;i&#41; time.sleep&#40;random.randrange&#40;10&#41;/50.0&#41; #time.sleep(1) print self.getName&#40;&#41;,'Finished' &#160; &#160; #...  <a href="http://fendou.org/2011/01/25/python-queue-lock/" class="more-link" title="Read Python Queue 的多线程(multi thread)死锁问题">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python和其他语言数据类型比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python和其他语言数据类型比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python解析iso8601时间格式获得时间戳" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python解析iso8601时间格式获得时间戳</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>废话不多说，先上代码：</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#encoding=utf-8</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">Queue</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">Queue</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">mutex</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Producer<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, threadname, queue, lock<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name = threadname<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">sharedata</span> = queue
        <span style="color: #008000;">self</span>.<span style="color: black;">lock</span> = lock
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span><span style="color: black;">&#41;</span>:
            <span style="color: #808080; font-style: italic;">#----------------</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">lock</span>.<span style="color: black;">acquire</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">self</span>.<span style="color: black;">getName</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'&lt;&lt; '</span>,i
            <span style="color: #008000;">self</span>.<span style="color: black;">lock</span>.<span style="color: black;">release</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #808080; font-style: italic;">#----------------</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">sharedata</span>.<span style="color: black;">put</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">50.0</span><span style="color: black;">&#41;</span>
            <span style="color: #808080; font-style: italic;">#time.sleep(1)</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">self</span>.<span style="color: black;">getName</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'Finished'</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Consumer thread</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Consumer<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">global</span> lock
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, threadname, queue, lock<span style="color: black;">&#41;</span>:
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name = threadname<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">sharedata</span> = queue
        <span style="color: #008000;">self</span>.<span style="color: black;">lock</span> = lock
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span><span style="color: black;">&#41;</span>:
            <span style="color: #808080; font-style: italic;">#----------------</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">lock</span>.<span style="color: black;">acquire</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">self</span>.<span style="color: black;">getName</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'        &gt;&gt; '</span>,<span style="color: #008000;">self</span>.<span style="color: black;">sharedata</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">lock</span>.<span style="color: black;">release</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #808080; font-style: italic;">#----------------</span>
            <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">50.0</span><span style="color: black;">&#41;</span>
            <span style="color: #808080; font-style: italic;">#time.sleep(1)</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">self</span>.<span style="color: black;">getName</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'Finished'</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Main thread</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
    lock = <span style="color: #dc143c;">threading</span>.<span style="color: black;">RLock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    queue = <span style="color: #dc143c;">Queue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    producer = Producer<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Producer'</span>, queue, lock<span style="color: black;">&#41;</span>
    consumer = Consumer<span style="color: black;">&#40;</span><span style="color: #483d8b;">'Consumer'</span>, queue, lock<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Starting threads ...'</span>
    producer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    consumer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    producer.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    consumer.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'All threads have terminated.'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>这个是在学习多线程的时候入门经典实例之一，这里只是加了个同步锁（RLock）<br />
多次执行这个脚本会发现，大部分时候这个脚本会发生死锁的现象，偶尔却能正确的执行完</p>
<p>这个问题并不是锁本身的问题，是程序的逻辑问题</p>
<p>producer和 consumer 都sleep  如下时间</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">50.0</span><span style="color: black;">&#41;</span></pre></div></div>

<p>当consumer  sleep时间小于producer 的时候而队列为空的时候就会发生貌似死锁的现象</p>
<p>之所以说是貌似，是因为这个并不是死锁引起的问题，而是queue 的get方法，这个方法有个timeout的可选参数，如果没有这个参数，那么get会一直等待队列中添加新的元素进来才会返回，所以后面的consumer 的 release并没有执行导致队列一直锁在那里，producer也没法写入，</p>
<p>关于queue  get方法的更详细用法请参阅<a href="http://docs.python.org/library/queue.html#Queue.Queue.get">python手册Queue章节</a></p>
<p>Python 的 queue 实现就是线程安全的，没有必要上锁，这里就是因为 queue 内部的锁机制同你的锁冲突了，如果要是想自己控制的话，那么 queue 的 put 和 get 都得用 nowait 的方法</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python和其他语言数据类型比较" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python和其他语言数据类型比较</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python解析iso8601时间格式获得时间戳" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python解析iso8601时间格式获得时间戳</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2011/01/25/python-queue-lock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python满足你需要的50个模块</title>
		<link>http://fendou.org/2011/01/12/50-python-modules/</link>
		<comments>http://fendou.org/2011/01/12/50-python-modules/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 02:46:24 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Excellence Article]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=777</guid>
		<description><![CDATA[Python具有强大的扩展能力，网上有人列出了50个很棒的Python模块，包含几乎所有的需要：比如Databases，GUIs，Images, Sound, OS interaction, Web,以及其他。推荐收藏。 Graphical interface wxPython http://wxpython.org Graphical interface pyGtk http://www.pygtk.org Graphical interface pyQT http://www.riverbankcomputing.co.uk/pyqt/ Graphical interface Pmw http://pmw.sourceforge.net/ Graphical interface Tkinter 3000 http://effbot.org/zone/wck.htm Graphical interface Tix http://tix.sourceforge.net/ Database MySQLdb http://sourceforge.net/projects/mysql-python Database PyGreSQL http://www.pygresql.org/ Database Gadfly http://gadfly.sourceforge.net/ Database SQLAlchemy http://www.sqlalchemy.org/ Database psycopg http://www.initd.org/pub/software/psycopg/ Database kinterbasdb http://kinterbasdb.sourceforge.net/ Database cx_Oracle http://www.cxtools.net/default.aspx?nav=downloads Database pySQLite http://initd.org/tracker/pysqlite MSN Messenger msnlib http://auriga.wearlab.de/~alb/msnlib/ MSN Messenger pymsn http://telepathy.freedesktop.org/wiki/Pymsn MSN Messenger msnp http://msnp.sourceforge.net/ Network Twisted http://twistedmatrix.com/ Images PIL http://www.pythonware.com/products/pil/ Images gdmodule http://newcenturycomputers.net/projects/gdmodule.html...  <a href="http://fendou.org/2011/01/12/50-python-modules/" class="more-link" title="Read python满足你需要的50个模块">Read more &#187;</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python非贪婪、多行匹配正则表达式例子" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python非贪婪、多行匹配正则表达式例子</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>Python具有强大的扩展能力，网上有人列出了50个很棒的Python模块，包含几乎所有的需要：比如Databases，GUIs，Images, Sound, OS interaction, Web,以及其他。推荐收藏。</p>
<p>Graphical interface wxPython <a rel="nofollow" href="http://wxpython.org/" target="_blank">http://wxpython.org</a><br />
Graphical interface pyGtk <a rel="nofollow" href="http://www.pygtk.org/" target="_blank">http://www.pygtk.org</a><br />
Graphical interface pyQT <a rel="nofollow" href="http://www.riverbankcomputing.co.uk/pyqt/" target="_blank">http://www.riverbankcomputing.co.uk/pyqt/</a><br />
Graphical interface Pmw <a rel="nofollow" href="http://pmw.sourceforge.net/" target="_blank">http://pmw.sourceforge.net/</a><br />
Graphical interface Tkinter 3000 <a rel="nofollow" href="http://effbot.org/zone/wck.htm" target="_blank">http://effbot.org/zone/wck.htm</a><br />
Graphical interface Tix <a rel="nofollow" href="http://tix.sourceforge.net/" target="_blank">http://tix.sourceforge.net/</a></p>
<p>Database MySQLdb <a rel="nofollow" href="http://sourceforge.net/projects/mysql-python" target="_blank">http://sourceforge.net/projects/mysql-python</a><br />
Database PyGreSQL <a rel="nofollow" href="http://www.pygresql.org/" target="_blank">http://www.pygresql.org/</a><br />
Database Gadfly <a rel="nofollow" href="http://gadfly.sourceforge.net/" target="_blank">http://gadfly.sourceforge.net/</a><br />
Database SQLAlchemy <a rel="nofollow" href="http://www.sqlalchemy.org/" target="_blank">http://www.sqlalchemy.org/</a><br />
Database psycopg <a rel="nofollow" href="http://www.initd.org/pub/software/psycopg/" target="_blank">http://www.initd.org/pub/software/psycopg/</a><br />
Database kinterbasdb <a rel="nofollow" href="http://kinterbasdb.sourceforge.net/" target="_blank">http://kinterbasdb.sourceforge.net/</a><br />
Database cx_Oracle <a rel="nofollow" href="http://www.cxtools.net/default.aspx?nav=downloads" target="_blank">http://www.cxtools.net/default.aspx?nav=downloads</a><br />
Database pySQLite <a rel="nofollow" href="http://initd.org/tracker/pysqlite" target="_blank">http://initd.org/tracker/pysqlite</a></p>
<p>MSN Messenger msnlib <a rel="nofollow" href="http://auriga.wearlab.de/~alb/msnlib/" target="_blank">http://auriga.wearlab.de/~alb/msnlib/</a><br />
MSN Messenger pymsn <a rel="nofollow" href="http://telepathy.freedesktop.org/wiki/Pymsn" target="_blank">http://telepathy.freedesktop.org/wiki/Pymsn</a><br />
MSN Messenger msnp <a rel="nofollow" href="http://msnp.sourceforge.net/" target="_blank">http://msnp.sourceforge.net/</a><br />
Network Twisted <a rel="nofollow" href="http://twistedmatrix.com/" target="_blank">http://twistedmatrix.com/</a><br />
Images PIL <a rel="nofollow" href="http://www.pythonware.com/products/pil/" target="_blank">http://www.pythonware.com/products/pil/</a><br />
Images gdmodule <a rel="nofollow" href="http://newcenturycomputers.net/projects/gdmodule.html" target="_blank">http://newcenturycomputers.net/projects/gdmodule.html</a><br />
Images VideoCapture <a rel="nofollow" href="http://videocapture.sourceforge.net/" target="_blank">http://videocapture.sourceforge.net/</a></p>
<p>Sciences and Maths scipy <a rel="nofollow" href="http://www.scipy.org/" target="_blank">http://www.scipy.org/</a><br />
Sciences and Maths NumPy <a rel="nofollow" href="http://numpy.scipy.org//" target="_blank">http://numpy.scipy.org//</a><br />
Sciences and Maths numarray <a rel="nofollow" href="http://www.stsci.edu/resources/software_hardware/numarray" target="_blank">http://www.stsci.edu/resources/software_hardware/numarray</a><br />
Sciences and Maths matplotlib <a rel="nofollow" href="http://matplotlib.sourceforge.net/" target="_blank">http://matplotlib.sourceforge.net/</a></p>
<p>Games Pygame <a rel="nofollow" href="http://www.pygame.org/news.html" target="_blank">http://www.pygame.org/news.html</a><br />
Games Pyglet <a rel="nofollow" href="http://www.pyglet.org/" target="_blank">http://www.pyglet.org/</a><br />
Games PySoy <a rel="nofollow" href="http://www.pysoy.org/" target="_blank">http://www.pysoy.org/</a><br />
Games pyOpenGL <a rel="nofollow" href="http://pyopengl.sourceforge.net/" target="_blank">http://pyopengl.sourceforge.net/<br />
</a>Jabber jabberpy<a rel="nofollow" href="http://pyopengl.sourceforge.net/" target="_blank"> </a><a rel="nofollow" href="http://jabberpy.sourceforge.net/" target="_blank">http://jabberpy.sourceforge.net/</a><br />
Web scrape <a rel="nofollow" href="http://zesty.ca/python/scrape.html" target="_blank">http://zesty.ca/python/scrape.html</a><br />
Web Beautiful Soup <a rel="nofollow" href="http://crummy.com/software/BeautifulSoup" target="_blank">http://crummy.com/software/BeautifulSoup</a><br />
Web pythonweb <a rel="nofollow" href="http://www.pythonweb.org/" target="_blank">http://www.pythonweb.org/</a><br />
Web mechanize <a rel="nofollow" href="http://wwwsearch.sourceforge.net/mechanize/" target="_blank">http://wwwsearch.sourceforge.net/mechanize/</a></p>
<p>Localisation geoname.py <a rel="nofollow" href="http://www.zindep.com/blog-zindep/Geoname-python/" target="_blank">http://www.zindep.com/blog-zindep/Geoname-python/</a></p>
<p>Serial port pySerial <a rel="nofollow" href="http://pyserial.sourceforge.net/" target="_blank">http://pyserial.sourceforge.net/</a><br />
Serial port USPP <a rel="nofollow" href="http://ibarona.googlepages.com/uspp" target="_blank">http://ibarona.googlepages.com/uspp</a></p>
<p>Parallel Port pyParallel <a rel="nofollow" href="http://pyserial.sourceforge.net/pyparallel.html" target="_blank">http://pyserial.sourceforge.net/pyparallel.html</a></p>
<p>USB Port pyUSB <a rel="nofollow" href="http://bleyer.org/pyusb/" target="_blank">http://bleyer.org/pyusb/</a></p>
<p>Windows ctypes <a rel="nofollow" href="http://starship.python.net/crew/theller/ctypes/" target="_blank">http://starship.python.net/crew/theller/ctypes/</a><br />
Windows pywin32 <a rel="nofollow" href="http://sourceforge.net/projects/pywin32/" target="_blank">http://sourceforge.net/projects/pywin32/</a><br />
Windows pywinauto <a rel="nofollow" href="http://www.openqa.org/pywinauto/" target="_blank">http://www.openqa.org/pywinauto/</a><br />
Windows pyrtf <a rel="nofollow" href="http://pyrtf.sourceforge.net/" target="_blank">http://pyrtf.sourceforge.net/</a><br />
Windows wmi <a rel="nofollow" href="http://timgolden.me.uk/python/wmi.html" target="_blank">http://timgolden.me.uk/python/wmi.html</a></p>
<p>PDA/GSM/Mobiles pymo <a rel="nofollow" href="http://www.awaretek.com/pymo.html" target="_blank">http://www.awaretek.com/pymo.html</a><br />
PDA/GSM/Mobiles pyS60 <a rel="nofollow" href="http://sourceforge.net/projects/pys60" target="_blank">http://sourceforge.net/projects/pys60</a></p>
<p>Sound pySoundic <a rel="nofollow" href="http://pysonic.sourceforge.net/" target="_blank">http://pysonic.sourceforge.net/</a><br />
Sound pyMedia <a rel="nofollow" href="http://pymedia.org/" target="_blank">http://pymedia.org/</a><br />
Sound FMOD <a rel="nofollow" href="http://www.fmod.org/" target="_blank">http://www.fmod.org/</a><br />
Sound pyMIDI <a rel="nofollow" href="http://www.cs.unc.edu/Research/assist/developer.shtml" target="_blank">http://www.cs.unc.edu/Research/assist/developer.shtml</a></p>
<p>GMail libgmail <a rel="nofollow" href="http://libgmail.sourceforge.net/" target="_blank">http://libgmail.sourceforge.net/</a><br />
Google pyGoogle <a rel="nofollow" href="http://pygoogle.sourceforge.net/" target="_blank">http://pygoogle.sourceforge.net/</a><br />
Expect pyExpect <a rel="nofollow" href="http://pexpect.sourceforge.net/" target="_blank">http://pexpect.sourceforge.net/</a><br />
WordNet pyWordNet <a rel="nofollow" href="http://osteele.com/projects/pywordnet/" target="_blank">http://osteele.com/projects/pywordnet/</a><br />
Command line cmd <a rel="nofollow" href="http://blog.doughellmann.com/2008/05/pymotw-cmd.html" target="_blank">http://blog.doughellmann.com/2008/05/pymotw-cmd.html</a><br />
Compiler backend llvm-py <a rel="nofollow" href="http://mdevan.nfshost.com/llvm-py/" target="_blank">http://mdevan.nfshost.com/llvm-py/</a><br />
3D VPython <a rel="nofollow" href="http://vpython.org/" target="_blank">http://vpython.org</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="python非贪婪、多行匹配正则表达式例子" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">python非贪婪、多行匹配正则表达式例子</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2011%2F01%2F12%2F50-python-modules%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2011/01/12/50-python-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python解析iso8601时间格式获得时间戳</title>
		<link>http://fendou.org/2010/11/21/python-parse-iso8601/</link>
		<comments>http://fendou.org/2010/11/21/python-parse-iso8601/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 02:28:04 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=754</guid>
		<description><![CDATA[关于iso8601数据交换标准，请参见维基百科的解释，中文版不完全解释，参见为维基百科中文版 常见示例格式如下： 2010-11-21T00:00:00+08:00 真实的案例，请参见美团网的团购API Python默认安装包中不能对iso8601格式的时间戳，因此先安装这个解析包，下载地址：http://pypi.python.org/pypi/iso8601/ 如果你不能在网站上找到对应Python版本的模块，也可以通过输入easy_install iso8601试试，我的是2.6版本，安装成功 解析过程很简单，代码如下: import time import iso8601 dt = iso8601.parse_date&#40;'2010-11-21T00:00:00+08:00'&#41; timestamp = time.mktime&#40;dt.timetuple&#40;&#41;&#41; PS:感谢妖怪帮助我解决解析iso8601时间格式的问题<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python和其他语言数据类型比较</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%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows平台安装Python2.6 和 MySQL-Python</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%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python Queue 的多线程(multi thread)死锁问题</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%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Httpsqs Python Client</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%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python 批量生成缩略图</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>关于iso8601数据交换标准，请参见<a href="http://en.wikipedia.org/wiki/ISO_8601">维基百科的解释</a>，中文版不完全解释，参见为<a href="http://zh.wikipedia.org/zh/ISO_8601">维基百科中文版</a><br />
常见示例格式如下：</p>
<blockquote><p>2010-11-21T00:00:00+08:00</p></blockquote>
<p>真实的案例，请参见<a href="view-source:http://www.meituan.com/api/v1/beijing/deals">美团网的团购API</a></p>
<p>Python默认安装包中不能对iso8601格式的时间戳，因此先安装这个解析包，下载地址：<a href="http://pypi.python.org/pypi/iso8601/">http://pypi.python.org/pypi/iso8601/</a><br />
如果你不能在网站上找到对应Python版本的模块，也可以通过输入easy_install iso8601试试，我的是2.6版本，安装成功<br />
解析过程很简单，代码如下:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> iso8601
dt = iso8601.<span style="color: black;">parse_date</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'2010-11-21T00:00:00+08:00'</span><span style="color: black;">&#41;</span>
timestamp = <span style="color: #dc143c;">time</span>.<span style="color: black;">mktime</span><span style="color: black;">&#40;</span>dt.<span style="color: black;">timetuple</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>PS:感谢<a href="http://www.dualface.com/blog/">妖怪</a>帮助我解决解析iso8601时间格式的问题</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  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%2Ffendou.org%2F2009%2F03%2F16%2Fpython-and-programming%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python和其他语言数据类型比较</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%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Windows平台安装Python2.6 和 MySQL-Python</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%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python Queue 的多线程(multi thread)死锁问题</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%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Httpsqs Python Client</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%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Python 批量生成缩略图</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://fendou.org/2010/11/21/python-parse-iso8601/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python中给urllib2设置超时时间</title>
		<link>http://fendou.org/2010/11/21/python-urllib2-set-timeout/</link>
		<comments>http://fendou.org/2010/11/21/python-urllib2-set-timeout/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 02:12:29 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=751</guid>
		<description><![CDATA[import socket import urllib2 &#160; socket.setdefaulttimeout&#40;seconds&#41; &#160; open = urllib2.urlopen&#40;&#34;http://xxx.xxx.xxx&#34;&#41; urllib2本身是没有办法设置超时时间的，示例中是通过socket.setdefaulttimeout() 设置了全局默认超时时间，从而给urllib2.urlopen()也设置了默认的超时时间<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python 批量生成缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python 批量生成缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python Queue 的多线程(multi thread)死锁问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python Queue 的多线程(multi thread)死锁问题</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
&nbsp;
<span style="color: #dc143c;">socket</span>.<span style="color: black;">setdefaulttimeout</span><span style="color: black;">&#40;</span>seconds<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #008000;">open</span> = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://xxx.xxx.xxx&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>urllib2本身是没有办法设置超时时间的，示例中是通过socket.setdefaulttimeout() 设置了全局默认超时时间，从而给urllib2.urlopen()也设置了默认的超时时间</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python 批量生成缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-thumb-image%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python 批量生成缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python Queue 的多线程(multi thread)死锁问题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fpython-queue-lock%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python Queue 的多线程(multi thread)死锁问题</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-urllib2-set-timeout%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2010/11/21/python-urllib2-set-timeout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>python非贪婪、多行匹配正则表达式例子</title>
		<link>http://fendou.org/2010/11/19/python-multi-line-non-greedy-regular-expression-sample/</link>
		<comments>http://fendou.org/2010/11/19/python-multi-line-non-greedy-regular-expression-sample/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 04:51:35 +0000</pubDate>
		<dc:creator>崔玉松</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://fendou.org/?p=746</guid>
		<description><![CDATA[一些regular的tips： 1 非贪婪flag >>> re.findall(r”a(\d+?)”, “a23b”) ['2'] >>> re.findall(r”a(\d+)”, “a23b”) ['23'] 注意比较这种情况： >>> re.findall(r”a(\d+)b”, “a23b”) ['23'] >>> re.findall(r”a(\d+?)b”, “a23b”) ['23'] 2 如果你要多行匹配，那么加上re.S和re.M标志 re.S：.将会匹配换行符，默认.不会匹配换行符 >>> re.findall(r”a(\d+)b.+a(\d+)b”, “a23b\na34b”) [] >>> re.findall(r”a(\d+)b.+a(\d+)b”, “a23b\na34b”, re.S) [('23', '34')] >>> re.M：^$标志将会匹配每一行，默认^和$只会匹配第一行 >>> re.findall(r”^a(\d+)b”, “a23b\na34b”) ['23'] >>> re.findall(r”^a(\d+)b”, “a23b\na34b”, re.M) ['23', '34'] 但是，如果没有^标志， >>> re.findall(r”a(\d+)b”, “a23b\na23b”) ['23', '23'] 可见，是无需re.M<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python解析iso8601时间格式获得时间戳" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python解析iso8601时间格式获得时间戳</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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>一些regular的tips：</p>
<p>1 非贪婪flag</p>
<blockquote><p>>>> re.findall(r”a(\d+?)”, “a23b”)<br />
        ['2']<br />
>>> re.findall(r”a(\d+)”, “a23b”)<br />
        ['23']</p></blockquote>
<p>注意比较这种情况：</p>
<blockquote><p>>>> re.findall(r”a(\d+)b”, “a23b”)<br />
        ['23']<br />
>>> re.findall(r”a(\d+?)b”, “a23b”)<br />
        ['23']</p></blockquote>
<p>2 如果你要多行匹配，那么加上re.S和re.M标志<br />
re.S：.将会匹配换行符，默认.不会匹配换行符</p>
<blockquote><p>>>> re.findall(r”a(\d+)b.+a(\d+)b”, “a23b\na34b”)<br />
        []<br />
>>> re.findall(r”a(\d+)b.+a(\d+)b”, “a23b\na34b”, re.S)<br />
        [('23', '34')]<br />
>>></p></blockquote>
<p>re.M：^$标志将会匹配每一行，默认^和$只会匹配第一行</p>
<blockquote><p>>>> re.findall(r”^a(\d+)b”, “a23b\na34b”)<br />
        ['23']<br />
>>> re.findall(r”^a(\d+)b”, “a23b\na34b”, re.M)<br />
        ['23', '34']</p></blockquote>
<p>但是，如果没有^标志，</p>
<blockquote><p>>>> re.findall(r”a(\d+)b”, “a23b\na23b”)<br />
        ['23', '23']</p></blockquote>
<p>可见，是无需re.M</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="Python PIL 生成带阴影的缩略图" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F31%2Fpython-pil-shadow-thumb%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/20/11136487.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python PIL 生成带阴影的缩略图</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Windows平台安装Python2.6 和 MySQL-Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F06%2F17%2Finstall-python26-mysql-python-on-windows%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Windows平台安装Python2.6 和 MySQL-Python</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="超级简单Python Socket Server一例" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F08%2F05%2Fpython-socket-server-simple-example%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/20/14185006.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">超级简单Python Socket Server一例</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Httpsqs Python Client" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2011%2F01%2F25%2Fhttpsqs-python-client%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Httpsqs Python Client</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Python解析iso8601时间格式获得时间戳" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ffendou.org%2F2010%2F11%2F21%2Fpython-parse-iso8601%2F&from=http%3A%2F%2Ffendou.org%2F2010%2F11%2F19%2Fpython-multi-line-non-greedy-regular-expression-sample%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Python解析iso8601时间格式获得时间戳</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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://fendou.org/2010/11/19/python-multi-line-non-greedy-regular-expression-sample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

