<?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; Python</title>
	<atom:link href="http://blog.caifeng.me/tag/python/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>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>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 good structure practice of Django project</title>
		<link>http://blog.caifeng.me/2008/12/18/a-good-structure-practice-of-django-project/</link>
		<comments>http://blog.caifeng.me/2008/12/18/a-good-structure-practice-of-django-project/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 15:43:04 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=6</guid>
		<description><![CDATA[I want to share a directory structure comes from my Django project.
Here is basic structure:

/PROJECT/manage.py &#40;under svn&#41;
/PROJECT/__init__.py &#40;under svn&#41;
/PROJECT/urls.py &#40;under svn&#41;
/PROJECT/settings.py &#40;under svn&#41;
/PROJECT/local_settings.py &#40;not under svn&#41;
/PROJECT/env.sh &#40;not under svn&#41;
/PROJECT/run &#40;not under svn&#41;
/PROJECT/apps &#40;under svn&#41;
/PROJECT/docs &#40;under svn&#41;
/PROJECT/static &#40;under svn&#41;
/PROJECT/templates &#40;under svn&#41;
/PROJECT/tests &#40;under svn&#41;
/PROJECT/scripts &#40;under svn&#41;
/PROJECT/initial_data &#40;under svn&#41;
/PROJECT/middlewares &#40;under svn&#41;
/PROJECT/patches &#40;under svn&#41;
/PROJECT/logs &#40;not under svn&#41;
/PROJECT/tmp &#40;not under [...]]]></description>
			<content:encoded><![CDATA[<p>I want to share a directory structure comes from my Django project.</p>
<p>Here is basic structure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>manage.py <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>__init__.py <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>urls.py <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>settings.py <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>local_settings.py <span style="color: #7a0874; font-weight: bold;">&#40;</span>not under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>env.sh <span style="color: #7a0874; font-weight: bold;">&#40;</span>not under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>run <span style="color: #7a0874; font-weight: bold;">&#40;</span>not under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>apps <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>docs <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>static <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>templates <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>tests <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>scripts <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>initial_data <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>middlewares <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>patches <span style="color: #7a0874; font-weight: bold;">&#40;</span>under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>logs <span style="color: #7a0874; font-weight: bold;">&#40;</span>not under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>PROJECT<span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #7a0874; font-weight: bold;">&#40;</span>not under <span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Here is the detail for each item.</p>
<ol>
<li>manage.py and __init__.py are default, you don&#8217;t need to change them.</li>
<li>urls.py. Actually, we didn&#8217;t not write the url patterns in this file, we just include the url patterns from apps.urls in this file</li>
<li>settings.py and local_settings.py. You must import local_settings.py from settings.py. In the settings.py, you have generic configuration. So you can add this file in the subversion. For in local_settings.py, we will put some particular settings based different environment. You don&#8217;t need to worry about breaking other&#8217;s environment by checking in the settings.py file any more.</li>
<li>env.sh. This is a key file in this structure. With my experience, some rookies are always bothered by kinds of module not found issues. In this file you need at least add these two environment variable. They&#8217;re PYTHONPATH and DJANGO_SETTINGS_MODULE. I always add a PROJECT_HOME variable, and then I can use this later in my shell scripts. That&#8217;s very very useful.</li>
<li>run. This a shell wrapping of manage.py.  That&#8217;s because you always need some environment setup before you run the manage.py. Here is a example</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PYTHONPATH</span>=<span style="color: #007800;">$PROJECT_HOME</span>:<span style="color: #007800;">$PYTHONPATH</span>
<span style="color: #007800;">DJANGO_SETTINGS_MODULE</span>=settings
python2.5 manage.py <span style="color: #007800;">$*</span></pre></div></div>

<li>apps directory, it&#8217;s the directory hold all of the apps.</li>
<li>docs, we always put kinds of document about the project here, such as deploy document</li>
<li>static directory, the static pages are always located here.</li>
<li>templates, we put template here.</li>
<li>tests, we plan to put the QA&#8217;s test cases there. We also will put some unit test there.</li>
<li>scripts, some dba scripts located here.</li>
<li>initial_data: The basic database of the site.</li>
<li>patches and tmp directory is rarely used.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2008/12/18/a-good-structure-practice-of-django-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

