<?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>梁剑的Blog &#187; Python</title>
	<atom:link href="http://icomes.net/tag/an-alternative-shell-or-script-or-language/feed/" rel="self" type="application/rss+xml" />
	<link>http://icomes.net</link>
	<description>做有趣的事，做有用的人</description>
	<lastBuildDate>Sat, 05 Nov 2011 18:23:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>监控iPhone 4S发布的Python脚本</title>
		<link>http://icomes.net/2011/11/03/%e7%9b%91%e6%8e%a7iphone-4s%e5%8f%91%e5%b8%83%e7%9a%84python%e8%84%9a%e6%9c%ac/</link>
		<comments>http://icomes.net/2011/11/03/%e7%9b%91%e6%8e%a7iphone-4s%e5%8f%91%e5%b8%83%e7%9a%84python%e8%84%9a%e6%9c%ac/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 15:56:36 +0000</pubDate>
		<dc:creator>梁剑</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://icomes.net/?p=574</guid>
		<description><![CDATA[但愿不用等太晚：） #!/usr/bin/python &#160; import urllib2 import sys import time &#160; def alarm&#40;&#41;: while True: sys.stdout.write&#40;'\a'&#41; sys.stdout.flush&#40;&#41; &#160; def poll&#40;&#41;: count=0; while True: count = count + 1 now = time.localtime&#40; time.time&#40;&#41; &#41; print '%02d:%02d:%02d %d' % &#40;now.tm_hour, now.tm_min, now.tm_sec, count&#41; try: urllib2.urlopen&#40;'http://store.apple.com/hk-zh/browse/home/shop_iphone/family/iphone/iphone4s'&#41; alarm&#40;&#41; except urllib2.HTTPError as error: pass #print error &#160; try: iphone4 = urllib2.urlopen&#40; [...]<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%2Ficomes.net%2F2011%2F02%2F13%2Fzen-of-python%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">The Zen of 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%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%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%2Ficomes.net%2F2009%2F04%2F19%2Fiphone-22-firmware%25E4%25B8%258B%25E8%25BD%25BD%25E5%259C%25B0%25E5%259D%2580%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">iPhone 2.2 firmware下载地址</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%2Ficomes.net%2F2009%2F04%2F06%2Fubunt904%25E7%25BB%2588%25E4%25BA%258E%25E5%258F%2591%25E5%25B8%2583%25E4%25BA%2586%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ubunt9.04终于发布了</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>但愿不用等太晚：）</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> alarm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
		<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\a</span>'</span><span style="color: black;">&#41;</span>
		<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> poll<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	count=<span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
		count = count + <span style="color: #ff4500;">1</span>
		now = <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'%02d:%02d:%02d %d'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>now.<span style="color: black;">tm_hour</span>, now.<span style="color: black;">tm_min</span>, now.<span style="color: black;">tm_sec</span>, count<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			<span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'http://store.apple.com/hk-zh/browse/home/shop_iphone/family/iphone/iphone4s'</span><span style="color: black;">&#41;</span>
			alarm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">HTTPError</span> <span style="color: #ff7700;font-weight:bold;">as</span> error:
			<span style="color: #ff7700;font-weight:bold;">pass</span>
			<span style="color: #808080; font-style: italic;">#print error</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			iphone4 = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'http://store.apple.com/hk-zh/browse/home/shop_iphone/family/iphone/iphone4'</span> <span style="color: black;">&#41;</span>
			html = <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span> iphone4.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> html.<span style="color: black;">find</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'iPhone 4S'</span> <span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= -<span style="color: #ff4500;">1</span> :
				alarm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">except</span>:
			<span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">#time.sleep(1)</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
	poll<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<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%2Ficomes.net%2F2011%2F02%2F13%2Fzen-of-python%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">The Zen of 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%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%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%2Ficomes.net%2F2009%2F04%2F19%2Fiphone-22-firmware%25E4%25B8%258B%25E8%25BD%25BD%25E5%259C%25B0%25E5%259D%2580%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">iPhone 2.2 firmware下载地址</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%2Ficomes.net%2F2009%2F04%2F06%2Fubunt904%25E7%25BB%2588%25E4%25BA%258E%25E5%258F%2591%25E5%25B8%2583%25E4%25BA%2586%2F&from=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Ubunt9.04终于发布了</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://icomes.net/2011/11/03/%e7%9b%91%e6%8e%a7iphone-4s%e5%8f%91%e5%b8%83%e7%9a%84python%e8%84%9a%e6%9c%ac/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>初学Python</title>
		<link>http://icomes.net/2009/01/24/%e5%88%9d%e5%ad%a6python/</link>
		<comments>http://icomes.net/2009/01/24/%e5%88%9d%e5%ad%a6python/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 18:22:57 +0000</pubDate>
		<dc:creator>梁剑</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[技术笔记]]></category>
		<category><![CDATA[数学]]></category>
		<category><![CDATA[概率]]></category>

		<guid isPermaLink="false">http://icomes.net/?p=292</guid>
		<description><![CDATA[这两天时间比较充裕，可以有比较长的连续时间集中精神，我用来学Python了。 有C++、Perl、Bash和PHP的基础，要入门其实并不太难。 没有关注太多的细节，套用很远古一句话，语言是用来写程序的，不是用来理解的。（粗体部分请用适当的词替换） 的确很方便，而且比Perl要容易，很多。 不过似乎Python不支持++运算符，无语。 另外，Python3和Python2不完全兼容，但对我是没有丝毫影响的：） 我主要的学习资料是网上的两个教程： Python 绝对简明手册 简明 Python 教程 都写得很好，如果是有其他语言的基础，看过应该就可以了解Python的基本用法了。 至于进一步的参考，找到了《Dive Into Python》的中文版，已经下载，作为工具书翻阅：） 趁着还记得一点，把前两天那个进化论中的概率论用Python重写了一次。 当然，结果一样，因为这个问题的数学期望是有理论保证的。 #!/usr/bin/python &#160; import os import random &#160; RandomCount=0; GenerateCount=0; Target = list&#40;&#34;tobeornottobe&#34;&#41;; &#160; def getRandomChar&#40;&#41;: global RandomCount; RandomCount = RandomCount+1; return random.choice&#40;&#34;abcdefghijklmnopqrstuvwxyz&#34;&#41;; &#160; def compareList&#40;list1, list2&#41;: if&#40; len&#40;list1&#41; != len&#40;list2&#41; &#41;: raise Exception; DifferentCount = 0; for [...]<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="The Zen of Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F02%2F13%2Fzen-of-python%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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;">The Zen of 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="监控iPhone 4S发布的Python脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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;">监控iPhone 4S发布的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="Ubuntu 8.04 Server在VMWare中无法启动的解决办法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2008%2F06%2F29%2Fubuntu-804-server%25E5%259C%25A8vmware%25E4%25B8%25AD%25E6%2597%25A0%25E6%25B3%2595%25E5%2590%25AF%25E5%258A%25A8%25E7%259A%2584%25E8%25A7%25A3%25E5%2586%25B3%25E5%258A%259E%25E6%25B3%2595%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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/06/29/15017346.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;">Ubuntu 8.04 Server在VMWare中无法启动的解决办法</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="Another Hello World is running on my iPhone!" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2009%2F08%2F30%2Fanother-hello-world-is-running-on-my-iphone%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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/06/29/15015234.png" 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;">Another Hello World is running on my iPhone!</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" 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了。<br />
有C++、Perl、Bash和PHP的基础，要入门其实并不太难。<br />
没有关注太多的细节，套用很远古一句话，<strong>语言</strong>是用来<strong>写程序</strong>的，不是用来<strong>理解</strong>的。（粗体部分请用适当的词替换）<br />
的确很方便，而且比Perl要容易，很多。<br />
不过似乎Python不支持++运算符，无语。<br />
另外，Python3和Python2不完全兼容，但对我是没有丝毫影响的：）</p>
<p>我主要的学习资料是网上的两个教程：</p>
<ol>
<li><a href="http://wiki.woodpecker.org.cn/moin/PyAbsolutelyZipManual" target="_blank">Python 绝对简明手册</a></li>
<li><a href="http://linux.chinaitlab.com/manual/Python_chinese/index.html" target="_blank"><span class="header">简明 Python 教程</span></a></li>
</ol>
<p><span class="header">都写得很好，如果是有其他语言的基础，看过应该就可以了解Python的基本用法了。</span></p>
<p><span class="header">至于进一步的参考，找到了<a href="http://www.woodpecker.org.cn/diveintopython/index.html" target="_blank">《Dive Into Python》的中文版</a>，已经下载，作为工具书翻阅：）<br />
</span></p>
<p>趁着还记得一点，把前两天那个<a href="http://icomes.net/?p=276" target="_blank">进化论中的概率论</a>用Python重写了一次。<br />
当然，结果一样，因为这个问题的数学期望是有理论保证的。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</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> <span style="color: #dc143c;">random</span>
&nbsp;
RandomCount=<span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</span>
GenerateCount=<span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</span>
Target = <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tobeornottobe&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getRandomChar<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">global</span> RandomCount<span style="color: #66cc66;">;</span>
	RandomCount = RandomCount+<span style="color: #ff4500;">1</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> compareList<span style="color: black;">&#40;</span>list1, list2<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>list1<span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>list2<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: #66cc66;">;</span>
	DifferentCount = <span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</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: #008000;">len</span><span style="color: black;">&#40;</span>list2<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> list1<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == list2<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">continue</span><span style="color: #66cc66;">;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			DifferentCount = DifferentCount+<span style="color: #ff4500;">1</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> DifferentCount<span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generateRandomList<span style="color: black;">&#40;</span>now, target<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">global</span> GenerateCount<span style="color: #66cc66;">;</span>
	GenerateCount = GenerateCount + <span style="color: #ff4500;">1</span><span style="color: #66cc66;">;</span>
	result = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</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: #008000;">len</span><span style="color: black;">&#40;</span>target<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> now<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= target<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>:
			result.<span style="color: black;">append</span><span style="color: black;">&#40;</span> getRandomChar<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
			<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> result<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == target<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>:
				now<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> = target<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			result.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">' '</span> <span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> result<span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">#	print result;</span>
&nbsp;
&nbsp;
Now = <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>Target<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">while</span> compareList<span style="color: black;">&#40;</span>Now, Target<span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span>:
	Result = generateRandomList<span style="color: black;">&#40;</span>Now, Target<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%6d&quot;</span> <span style="color: #66cc66;">%</span> GenerateCount, <span style="color: #483d8b;">&quot;|&quot;</span>, <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>Now<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;|&quot;</span>, <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>Result<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;RandomCount: &quot;</span>, RandomCount<span style="color: #66cc66;">;</span></pre></div></div>

<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><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="The Zen of Python" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F02%2F13%2Fzen-of-python%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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;">The Zen of 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="监控iPhone 4S发布的Python脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F11%2F03%2F%25E7%259B%2591%25E6%258E%25A7iphone-4s%25E5%258F%2591%25E5%25B8%2583%25E7%259A%2584python%25E8%2584%259A%25E6%259C%25AC%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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;">监控iPhone 4S发布的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="The Last Lecture" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2011%2F10%2F15%2Fthe-last-lecture%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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/10/15/9228539.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;">The Last Lecture</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="阅读空间的GM脚本" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ficomes.net%2F2009%2F01%2F17%2F%25E9%2598%2585%25E8%25AF%25BB%25E7%25A9%25BA%25E9%2597%25B4%25E7%259A%2584gs%25E8%2584%259A%25E6%259C%25AC%2F&from=http%3A%2F%2Ficomes.net%2F2009%2F01%2F24%2F%25E5%2588%259D%25E5%25AD%25A6python%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/06/29/15015260.png" 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;">阅读空间的GM脚本</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" 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://icomes.net/2009/01/24/%e5%88%9d%e5%ad%a6python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

