<?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>Cai Feng's Blog &#187; Developer</title>
	<atom:link href="http://blog.caifeng.me/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caifeng.me</link>
	<description>Paw trace ...</description>
	<lastBuildDate>Tue, 19 Oct 2010 16:53:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Array&#8217;s last comma affect it&#8217;s length in IE</title>
		<link>http://blog.caifeng.me/2010/10/20/arrays-last-comma-affect-its-length-in-ie/</link>
		<comments>http://blog.caifeng.me/2010/10/20/arrays-last-comma-affect-its-length-in-ie/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 16:53:31 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.caifeng.me/?p=90</guid>
		<description><![CDATA[
  var arr = &#91;1, 2, 3,&#93;;
  alert&#40;arr.length&#41;;

In firefox, the result is 3, but in IE, it is 4. It always takes some bugs which are hard to found. Right now, I don&#8217;t know which is the correct way, but I always remove the last comma safely.
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>arr.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In firefox, the result is 3, but in IE, it is 4. It always takes some bugs which are hard to found. Right now, I don&#8217;t know which is the correct way, but I always remove the last comma safely.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2010/10/20/arrays-last-comma-affect-its-length-in-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use google form as a simple survey system</title>
		<link>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/</link>
		<comments>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 06:35:22 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=67</guid>
		<description><![CDATA[Preview

A google form is a simple generally form system. You can use it to generate a form to ask your user some questions and collect the answers into a google spreadsheet automatically. And then you can do farther data analytics with that spreadsheet.
Actually, the google form can be used directly. But in some cases, the [...]]]></description>
			<content:encoded><![CDATA[<h4 id="Preview">Preview</h4>
<ul>
<li>A google form is a simple generally form system. You can use it to generate a form to ask your user some questions and collect the answers into a google spreadsheet automatically. And then you can do farther data analytics with that spreadsheet.</li>
<li>Actually, the google form can be used directly. But in some cases, the user want to change the google form&#8217;s default behavior to meet their requirements, such as they don&#8217;t want it to be redirected to google&#8217;s response page which have google&#8217;s logo there, they want to customize the design of the google form, etc</li>
<li>This scripts is used to focus on these special cases, also it can&#8217;t cover all of these cases, but it&#8217;s a beginning.</li>
</ul>
<h4>Design</h4>
<ul>
<li>I used a iframe to handle the google form&#8217;s default response.</li>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;">  &lt;form target=&quot;gsurvey_result&quot;&gt;&lt;/form&gt;
  &lt;iframe name=&quot;gsurvey_result&quot; height=&quot;1&quot; style=&quot;display:none;&quot;&gt;&lt;/iframe&gt;</pre></div></div>

<li>I used javascript to replace all of the radio button with a image, when the user clicks the image, the value of the radio will be synced directly. The image can be changed with css.</li>
<li>I used the javascript to check if the required field has a value. But now there&#8217;s nothing to do with the required field without a value.</li>
<li>User can define the response text by themselves.</li>
</ul>
<h4 id="Anexample">An example</h4>
<ul>
<li>Generate a google form with your own google account.</li>
<li>Create a new html file, load the script gsurvey.js, gsurvey.css in the html file.</li>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;link rel=&quot;stylesheet&quot; media=&quot;screen&quot; href=&quot;/static/css/gsurvey.css&quot; /&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;/static/js/jquery.gsurvey.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<li>Insert the html code of the google form. You can also define a element holds response text. You can check the code in the attachments.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance of str+str and ‘‘.join()</title>
		<link>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/</link>
		<comments>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 02:00:32 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=60</guid>
		<description><![CDATA[
&#62;&#62;&#62; a = 'a' * 100000
&#62;&#62;&#62; def t&#40;a&#41;:
&#62;&#62;&#62;     b = ''
&#62;&#62;&#62;     for i in a:
&#62;&#62;&#62;         b = b + '&#124;' + i
&#62;&#62;&#62;     return b
&#62;&#62;&#62; 
&#62;&#62;&#62; time c = t&#40;a&#41;
&#62;&#62;&#62; time c = '&#124;'.join&#40;a&#41;

In my notebook [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> a = <span style="color: #483d8b;">'a'</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">100000</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">def</span> t<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
<span style="color: #66cc66;">&gt;&gt;&gt;</span>     b = <span style="color: #483d8b;">''</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span>     <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> a:
<span style="color: #66cc66;">&gt;&gt;&gt;</span>         b = b + <span style="color: #483d8b;">'|'</span> + i
<span style="color: #66cc66;">&gt;&gt;&gt;</span>     <span style="color: #ff7700;font-weight:bold;">return</span> b
<span style="color: #66cc66;">&gt;&gt;&gt;</span> 
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #dc143c;">time</span> c = t<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #dc143c;">time</span> c = <span style="color: #483d8b;">'|'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span></pre></div></div>

<p>In my notebook ( Intel(R) Core(TM)2 CPU T5200  @ 1.60GHz, 1.5G Mem):</p>
<p>The result of time c=t(a):<br />
CPU times: user 2.90 s, sys: 0.00 s, total: 2.90 s<br />
Wall time: 3.07 s</p>
<p>The result of time c = &#8216;|&#8217;.join(a):<br />
CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s<br />
Wall time: 0.01 s</p>
<p>If I changed a from 100000 to 1000000, c=t(a) can&#8217;t give me a result in more than 5 minutes while the other one give me the result in 0.09s.</p>
<p>join is much faster than str + str. str + str need to create new strings all the time, but join doesn&#8217;t. I guess &#8220;join&#8221; maybe do something on the memory level.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>来自 &#8220;The Federated States of Micronesia&#8221; 的顾客</title>
		<link>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/</link>
		<comments>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 08:06:12 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=55</guid>
		<description><![CDATA[今天我们站点上出现了个跟国名有关的错误。一个来自&#8221;The Federated States of Micronesia&#8221;的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称&#8221;MICRONESIA, FEDERATED STATES OF&#8221;。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易，这样也能被拒绝，我估计这老兄一定这么想。)
这让我想起了个问题，不知道世界上最长的国家名称能有多少个字符？
写个blog纪念一下这位老兄的国家吧，也算长见识了。
http://en.wikipedia.org/wiki/Federated_States_of_Micronesia
]]></description>
			<content:encoded><![CDATA[<p>今天我们站点上出现了个跟国名有关的错误。一个来自&#8221;The Federated States of Micronesia&#8221;的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称&#8221;MICRONESIA, FEDERATED STATES OF&#8221;。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易，这样也能被拒绝，我估计这老兄一定这么想。)</p>
<p>这让我想起了个问题，不知道世界上最长的国家名称能有多少个字符？<br />
写个blog纪念一下这位老兄的国家吧，也算长见识了。</p>
<p>http://en.wikipedia.org/wiki/Federated_States_of_Micronesia</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分析日志常用到的几个shell工具</title>
		<link>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/</link>
		<comments>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 03:03:40 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/</guid>
		<description><![CDATA[一个不错的例子: http://nunojob.wordpress.com/2008/04/12/history-awk-print-2-sort-uniq-c-sort-rn-head/

httpd.log &#124; awk '{print $2}' \  &#124; sort &#124; uniq -c &#124; sort -rn &#124; head

解释:
httpd.log : 要分析的日志
awk : 用来取出某一特定的列。简单的也可以用cut来代替
sort : 用来排序(第一次排序是用来为后面的uniq服务的。uniq对于没有排序的内容工作不正确)
uniq : 用来uniq有序的内容，-c参数会把重复次数带上
sort -rn : 用来安重复次数倒序排列
head : 用来去前几条数据，默认是10.
]]></description>
			<content:encoded><![CDATA[<p>一个不错的例子: http://nunojob.wordpress.com/2008/04/12/history-awk-print-2-sort-uniq-c-sort-rn-head/</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">httpd.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> \  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-rn</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span></pre></div></div>

<p>解释:<br />
httpd.log : 要分析的日志<br />
awk : 用来取出某一特定的列。简单的也可以用cut来代替<br />
sort : 用来排序(第一次排序是用来为后面的uniq服务的。uniq对于没有排序的内容工作不正确)<br />
uniq : 用来uniq有序的内容，-c参数会把重复次数带上<br />
sort -rn : 用来安重复次数倒序排列<br />
head : 用来去前几条数据，默认是10.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Satchmo 新体验</title>
		<link>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/</link>
		<comments>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 15:55:27 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[satchmo]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/</guid>
		<description><![CDATA[今天checkout最新的satchmo看了一下，发现变化还是很大的。看样子我们的BE是没法升级到最新的satchmo了&#8230;
还没有时间仔细研究，不过发现有几个satchmo用到的第三方的app值得注意一下：
1. django-registration
http://code.google.com/p/django-registration/
这个已经用过几次，感觉不错，而且感觉它的生命力很强。
2. django-values
http://code.google.com/p/django-values/
satchmo用这个替换了原来自己写的configuration模块。我一直认为satchmo的configuration模块有设计上的缺陷，结果这次被彻底换掉了，不错。有时间研究一下这个。
3. threaded_multihost
http://gosatchmo.com/apps/django-threaded-multihost/
multi-site aware features， 不是很懂，还得看看代码。
]]></description>
			<content:encoded><![CDATA[<p>今天checkout最新的satchmo看了一下，发现变化还是很大的。看样子我们的BE是没法升级到最新的satchmo了&#8230;</p>
<p>还没有时间仔细研究，不过发现有几个satchmo用到的第三方的app值得注意一下：<br />
1. django-registration</p>
<p>http://code.google.com/p/django-registration/</p>
<p>这个已经用过几次，感觉不错，而且感觉它的生命力很强。<br />
2. django-values</p>
<p>http://code.google.com/p/django-values/</p>
<p>satchmo用这个替换了原来自己写的configuration模块。我一直认为satchmo的configuration模块有设计上的缺陷，结果这次被彻底换掉了，不错。有时间研究一下这个。<br />
3. threaded_multihost</p>
<p>http://gosatchmo.com/apps/django-threaded-multihost/</p>
<p>multi-site aware features， 不是很懂，还得看看代码。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[八卦] google music, 爽！</title>
		<link>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/</link>
		<comments>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 15:43:47 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/</guid>
		<description><![CDATA[今天看新闻发现google出了music搜索，于是试用了一把。 （http://www.google.cn/music/homepage)
搜歌，听歌，下载，一应俱全。
尤其是它的web播放器，用起来很舒服。
对于google的music搜索，有几个疑问:
1. 歌曲的下载地址不是链接到其他网站，而是统一链接到top100.cn
2. 上面可以下载的歌曲很新，不知道版权问题是如何解决的？
]]></description>
			<content:encoded><![CDATA[<p>今天看新闻发现google出了music搜索，于是试用了一把。 （http://www.google.cn/music/homepage)</p>
<p>搜歌，听歌，下载，一应俱全。<br />
尤其是它的web播放器，用起来很舒服。</p>
<p>对于google的music搜索，有几个疑问:<br />
1. 歌曲的下载地址不是链接到其他网站，而是统一链接到top100.cn<br />
2. 上面可以下载的歌曲很新，不知道版权问题是如何解决的？</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Normal method, @staticmethod, @classmethod of python</title>
		<link>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/</link>
		<comments>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 09:46:51 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=46</guid>
		<description><![CDATA[Reference:
http://snippets.dzone.com/posts/show/1679
http://www.geocities.com/foetsch/python/new_style_classes.htm
Check the doctest in these code bottom.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
&#34;&#34;&#34;
Test the variable methods in class
&#34;&#34;&#34;
&#160;
class K&#40;object&#41;:
    &#34;&#34;&#34;
    Test the variable methods in class
    &#62;&#62;&#62; k_obj = K()
    &#62;&#62;&#62; k_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &#62;&#62;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Reference:<br />
<a href="http://snippets.dzone.com/posts/show/1679">http://snippets.dzone.com/posts/show/1679</a><br />
<a href="http://www.geocities.com/foetsch/python/new_style_classes.htm">http://www.geocities.com/foetsch/python/new_style_classes.htm</a></p>
<p>Check the doctest in these code bottom.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
Test the variable methods in class
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> K<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Test the variable methods in class
    &gt;&gt;&gt; k_obj = K()
    &gt;&gt;&gt; k_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &gt;&gt;&gt; K.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.K'&gt;)
    &gt;&gt;&gt; k_obj.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.K'&gt;)
    &gt;&gt;&gt; K.method3()
    staticmethod: K.method3() become just method3(None)
    &gt;&gt;&gt; k_obj.method3()
    staticmethod: K.method3() become just method3(None)
    &quot;&quot;&quot;</span>
    <span style="color: #808080; font-style: italic;"># normal method (instance method)</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> method1<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;">print</span> <span style="color: #483d8b;">'Normal method: obj.method1() becomes method1(obj)'</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># class method</span>
    @<span style="color: #008000;">classmethod</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> method2<span style="color: black;">&#40;</span>cls<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'classmethod: K.method2() becomes method2(klass: %s)'</span> <span style="color: #66cc66;">%</span> cls
&nbsp;
    <span style="color: #808080; font-style: italic;"># static method</span>
    @<span style="color: #008000;">staticmethod</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> method3<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;">'staticmethod: K.method3() become just method3(None)'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> KK<span style="color: black;">&#40;</span>K<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Test the variable methods' behavior in the subclass.
    &gt;&gt;&gt; kk_obj = KK()
    &gt;&gt;&gt; kk_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &gt;&gt;&gt; KK.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.KK'&gt;)
    &gt;&gt;&gt; kk_obj.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.KK'&gt;)
    &gt;&gt;&gt; KK.method3()
    staticmethod: K.method3() become just method3(None)
    &gt;&gt;&gt; kk_obj.method3()
    staticmethod: K.method3() become just method3(None)
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">pass</span> 
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">doctest</span>
    <span style="color: #dc143c;">doctest</span>.<span style="color: black;">testmod</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A good example to explain *args and **kwargs in python</title>
		<link>http://blog.caifeng.me/2009/03/10/a-good-example-to-understand-args-and-kwargs-in-python/</link>
		<comments>http://blog.caifeng.me/2009/03/10/a-good-example-to-understand-args-and-kwargs-in-python/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 10:52:36 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=33</guid>
		<description><![CDATA[I read this wonderful example here: http://www.megasolutions.net/python/-args-and&#8212;kwargs-78766.aspx

&#62;&#62;&#62; def a&#40;*stuff&#41;:
                 print repr&#40;stuff&#41;
&#62;&#62;&#62; def b&#40;**stuff&#41;:
                 print repr&#40;stuff&#41;
&#62;&#62;&#62; def c&#40;*args, **kwargs&#41;:
      [...]]]></description>
			<content:encoded><![CDATA[<p>I read this wonderful example here: http://www.megasolutions.net/python/-args-and&#8212;kwargs-78766.aspx</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">def</span> a<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>stuff<span style="color: black;">&#41;</span>:
                 <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>stuff<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">def</span> b<span style="color: black;">&#40;</span><span style="color: #66cc66;">**</span>stuff<span style="color: black;">&#41;</span>:
                 <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>stuff<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">def</span> c<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
                 <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'args'</span>, <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span>
                 <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'kwargs'</span>, <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>kwargs<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b<span style="color: black;">&#40;</span>hello=<span style="color: #483d8b;">'world'</span>, lingo=<span style="color: #483d8b;">'python'</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#123;</span><span style="color: #483d8b;">'hello'</span>: <span style="color: #483d8b;">'world'</span>, <span style="color: #483d8b;">'lingo'</span>: <span style="color: #483d8b;">'python'</span><span style="color: black;">&#125;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c<span style="color: black;">&#40;</span><span style="color: #ff4500;">13</span>,<span style="color: #ff4500;">14</span>,thenext=<span style="color: #ff4500;">16</span>,afterthat=<span style="color: #ff4500;">17</span><span style="color: black;">&#41;</span>
args <span style="color: black;">&#40;</span><span style="color: #ff4500;">13</span>, <span style="color: #ff4500;">14</span><span style="color: black;">&#41;</span>
kwargs <span style="color: black;">&#123;</span><span style="color: #483d8b;">'afterthat'</span>: <span style="color: #ff4500;">17</span>, <span style="color: #483d8b;">'thenext'</span>: <span style="color: #ff4500;">16</span><span style="color: black;">&#125;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> args = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> kwargs = <span style="color: black;">&#123;</span><span style="color: #483d8b;">'no-way'</span>: <span style="color: #ff4500;">23</span>, <span style="color: #483d8b;">'yet-anotherInvalid.name'</span>: <span style="color: #ff4500;">24</span><span style="color: black;">&#125;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c<span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
args <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>
kwargs <span style="color: black;">&#123;</span><span style="color: #483d8b;">'no-way'</span>: <span style="color: #ff4500;">23</span>, <span style="color: #483d8b;">'yet-anotherInvalid.name'</span>: <span style="color: #ff4500;">24</span><span style="color: black;">&#125;</span></pre></div></div>

<p>Here is some simple explaination about *args and **kwargs</p>
<p>Basically &#8216;args&#8217; is a tuple with all the positional arguments, kwargs is a dictionary with all the named arguments.<br />
Likewise you can pass a tuple to a function like func(*tuple), or a dict like func(**dictionary) or both, where the zuple has to come first. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/10/a-good-example-to-understand-args-and-kwargs-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A project list I want to do.</title>
		<link>http://blog.caifeng.me/2009/01/08/a-project-list-i-want-to-do/</link>
		<comments>http://blog.caifeng.me/2009/01/08/a-project-list-i-want-to-do/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 08:04:46 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Developer]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=17</guid>
		<description><![CDATA[1. Write a script to sync the tickets from trac to platform(Platform is a internal project.). I don&#8217;t need to create the ticket in the trac and copy it to the platform. It&#8217;s a waste.
2. Improve google code: getsong project. I want to get the top 500 song list from http://www.9sky.com/ and download the song [...]]]></description>
			<content:encoded><![CDATA[<p>1. Write a script to sync the tickets from trac to platform(Platform is a internal project.). I don&#8217;t need to create the ticket in the trac and copy it to the platform. It&#8217;s a waste.</p>
<p>2. Improve google code: <a href="http://code.google.com/p/getsong/">getsong</a> project. I want to get the top 500 song list from http://www.9sky.com/ and download the song with getsong script.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/01/08/a-project-list-i-want-to-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

