<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3967080224183399920</id><updated>2011-04-21T18:19:18.673-07:00</updated><category term='google app engine'/><category term='python software'/><category term='django view'/><category term='django routing'/><category term='google api'/><category term='python general'/><category term='django general'/><title type='text'>deeply love python</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>47</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-30326169239111292</id><published>2008-12-29T20:35:00.000-08:00</published><updated>2009-01-14T07:55:00.175-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google api'/><title type='text'>google blogger data api  &amp; app engine</title><content type='html'>&lt;div&gt; &lt;a href="http://code.google.com/p/google-app-engine-samples/source/browse/trunk/gdata_feedfetcher/?r=61"&gt;gdata feed fetcher code&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;get project code:    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;    svn co http://google-app-engine-samples.googlecode.com/svn/trunk/gdata_feedfetcher&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;  install:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    1. get gdata library&lt;/div&gt;&lt;div&gt;        &lt;a href="http://code.google.com/p/gdata-python-client/"&gt;http://code.google.com/p/gdata-python-client/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;    2. copy gdata and atom directories of gdata-python-client library into project directory &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;get blogs updated at today:&lt;/span&gt;&lt;br /&gt;ex: if today is 2008-12-30, want to get blogs with tag "apple command"&lt;br /&gt;from url:&lt;br /&gt;&lt;a href="http://deeplyloveapple.blogspot.com/feeds/posts/default/-/apple%20command?updated-min=2008-12-30&amp;amp;orderby=updated"&gt;http://deeplyloveapple.blogspot.com/feeds/posts/default/-/apple%20command?updated-min=2008-12-30&amp;amp;orderby=updated&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-30326169239111292?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/30326169239111292/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=30326169239111292' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/30326169239111292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/30326169239111292'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/12/google-blogger-data-api.html' title='google blogger data api  &amp; app engine'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4645384951309450504</id><published>2008-09-04T22:06:00.000-07:00</published><updated>2008-09-04T22:07:42.521-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>URL mapping in app engine</title><content type='html'>defined in app.yaml&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;app.yaml defines which handler script will  handle the request(URL)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4645384951309450504?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4645384951309450504/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4645384951309450504' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4645384951309450504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4645384951309450504'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/09/url-mapping-in-app-engine.html' title='URL mapping in app engine'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-6700082767699043497</id><published>2008-09-03T06:35:00.000-07:00</published><updated>2008-09-03T06:37:07.869-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>google app engine video</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Campfire One: Introducing Google App Engine &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;a href="http://tw.youtube.com/watch?v=3Ztr-HhWX1c&amp;amp;eurl=http://code.google.com/appengine/articles/cf1-text.html"&gt;http://tw.youtube.com/watch?v=3Ztr-HhWX1c&amp;amp;eurl=http://code.google.com/appengine/articles/cf1-text.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-6700082767699043497?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/6700082767699043497/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=6700082767699043497' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6700082767699043497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6700082767699043497'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/09/google-app-engine-video.html' title='google app engine video'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3316959995963974393</id><published>2008-08-29T12:32:00.000-07:00</published><updated>2008-08-29T12:35:40.308-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>using django with app engine</title><content type='html'>1. create django project&lt;div&gt;   django-admin.py startproject Test&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. add main.py in project:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;# Google App Engine imports.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext.webapp import util&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from django.core.management import setup_environ&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import settings&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;setup_environ(settings)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;# Force Django to reload its settings.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from django.conf import settings&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;settings._target = None&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import django.core.handlers.wsgi&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import django.core.signals&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import django.db&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import django.dispatch.dispatcher&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;# Unregister the rollback event handler.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;django.dispatch.dispatcher.disconnect(&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;    django.db._rollback_on_exception,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;    django.core.signals.got_request_exception)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def main():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  # Create a Django application for WSGI.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  application = django.core.handlers.wsgi.WSGIHandler()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  # Run the WSGI CGI handler with that application.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  util.run_wsgi_app(application)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;if __name__ == '__main__':&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  main()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;3. add app.yaml in project&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;div&gt;application: test&lt;/div&gt;&lt;div&gt;version: 1&lt;/div&gt;&lt;div&gt;runtime: python&lt;/div&gt;&lt;div&gt;api_version: 1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;handlers:&lt;/div&gt;&lt;div&gt;- url: /.*&lt;/div&gt;&lt;div&gt;  script: main.py&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0);"&gt;4. dev_appserver.py  Test&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3316959995963974393?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3316959995963974393/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3316959995963974393' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3316959995963974393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3316959995963974393'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/using-django-with-app-engine.html' title='using django with app engine'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5635156018962316719</id><published>2008-08-28T22:07:00.000-07:00</published><updated>2008-08-28T22:08:29.901-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>webpage about django &amp; app engine</title><content type='html'>&lt;a href="http://www.42topics.com/dumps/django/docs.html"&gt;http://www.42topics.com/dumps/django/docs.html&lt;/a&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://www.42topics.com/dumps/appengine/doc.html"&gt;http://www.42topics.com/dumps/appengine/doc.html&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5635156018962316719?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5635156018962316719/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5635156018962316719' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5635156018962316719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5635156018962316719'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/webpage-about-django-app-engine.html' title='webpage about django &amp; app engine'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5546112924346484697</id><published>2008-08-28T07:50:00.000-07:00</published><updated>2008-08-28T08:03:48.510-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>create application on app engine</title><content type='html'>1. create an application from &lt;a href="http://appengine.google.com/"&gt;http://appengine.google.com/&lt;/a&gt;&lt;div&gt;    application identifier must be the same as application in app.yaml&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. upload application&lt;/div&gt;&lt;div&gt;    appcfg.py  update helloworld&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3. by default,&lt;/div&gt;&lt;div&gt;    the application url is  &lt;span class="Apple-style-span" style="font-size: medium;"&gt;http://helloworld.appspot.com/&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5546112924346484697?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5546112924346484697/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5546112924346484697' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5546112924346484697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5546112924346484697'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/create-application-on-app-engine.html' title='create application on app engine'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5082080406042695720</id><published>2008-08-28T07:41:00.000-07:00</published><updated>2008-08-28T07:45:28.530-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>using static files</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;using css:&lt;/span&gt;&lt;div&gt;add  following lines in yaml&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;- url: /stylesheets&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  static_dir: stylesheets&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;add a directory stylesheets under project directory &lt;/div&gt;&lt;div&gt;css files are in this directory&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;add following lines in html&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&amp;lt;head&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &amp;lt;link type="text/css" rel="stylesheet" href="/stylesheets/main.css" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &amp;lt;/head&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5082080406042695720?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5082080406042695720/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5082080406042695720' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5082080406042695720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5082080406042695720'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/using-static-files.html' title='using static files'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5559409381801958977</id><published>2008-08-26T21:51:00.000-07:00</published><updated>2008-08-26T21:52:19.684-07:00</updated><title type='text'>free svn server</title><content type='html'>assembla&lt;div&gt;&lt;a href="http://www.assembla.com"&gt;http://www.assembla.com&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5559409381801958977?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5559409381801958977/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5559409381801958977' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5559409381801958977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5559409381801958977'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/free-svn-server.html' title='free svn server'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4119813393983118688</id><published>2008-08-26T09:23:00.000-07:00</published><updated>2008-08-26T09:27:36.544-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>template in webapp</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;helloworld.py&lt;/span&gt;&lt;/div&gt;&lt;div&gt;import cgi&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;from google.appengine.ext import db&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import os&lt;/div&gt;&lt;div&gt;from google.appengine.ext.webapp import template&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;from google.appengine.ext import webapp&lt;/div&gt;&lt;div&gt;from google.appengine.ext.webapp.util import run_wsgi_app&lt;/div&gt;&lt;div&gt;from google.appengine.api import users&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;class Greeting(db.Model):&lt;/div&gt;&lt;div&gt;  author = db.UserProperty()&lt;/div&gt;&lt;div&gt;  content = db.StringProperty(multiline=True)&lt;/div&gt;&lt;div&gt;  date = db.DateTimeProperty(auto_now_add=True)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;class MainPage(webapp.RequestHandler):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;def get(self):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;greetings_query = Greeting.all().order('-date')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;greetings = greetings_query.fetch(10)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;if users.get_current_user():&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;url = users.create_logout_url(self.request.uri)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;url_linktext = 'Logout'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;else:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;url = users.create_login_url(self.request.uri)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;url_linktext = 'Login'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;template_values = {&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;  'greetings': greetings,&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;      'url': url,&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;      'url_linktext': url_linktext,&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;path = os.path.join(os.path.dirname(__file__), 'index.html')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;self.response.out.write(template.render(path, template_values))&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;class Guestbook(webapp.RequestHandler):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;def post(self):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; greeting = Greeting()&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; if users.get_current_user():&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;greeting.author = users.get_current_user()&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;greeting.content = self.request.get('content')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;greeting.put()&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;self.redirect('/')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;application = webapp.WSGIApplication( [('/', MainPage), ('/sign', Guestbook)], debug=True)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;def main():&lt;/div&gt;&lt;div&gt;  run_wsgi_app(application)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if __name__ == "__main__":&lt;/div&gt;&lt;div&gt;  main()&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;index.html&lt;/span&gt;:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&amp;lt;html&gt;&lt;/div&gt;&lt;div&gt;  &amp;lt;body&gt;&lt;/div&gt;&lt;div&gt;    {% for greeting in greetings %}&lt;/div&gt;&lt;div&gt;      {% if greeting.author %}&lt;/div&gt;&lt;div&gt;        &amp;lt;b&gt;{{ greeting.author.nickname }}&amp;lt;/b&gt; wrote:&lt;/div&gt;&lt;div&gt;      {% else %}&lt;/div&gt;&lt;div&gt;       An anonymous person wrote:&lt;/div&gt;&lt;div&gt;      {% endif %}&lt;/div&gt;&lt;div&gt;      &amp;lt;blockquote&gt;{{ greeting.content|escape }}&amp;lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;    {% endfor %}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    &amp;lt;form action="/sign" method="post"&gt;&lt;/div&gt;&lt;div&gt; &amp;lt;div&gt;&amp;lt;textarea name="content" rows="3" cols="60"&gt;&amp;lt;/textarea&gt;&amp;lt;/div&gt;&lt;/div&gt;&lt;div&gt;      &amp;lt;div&gt;&amp;lt;input type="submit" value="Sign Guestbook"&gt;&amp;lt;/div&gt;&lt;/div&gt;&lt;div&gt;    &amp;lt;/form&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    &amp;lt;a href="{{ url }}"&gt;{{ url_linktext }}&amp;lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  &amp;lt;/body&gt;&lt;/div&gt;&lt;div&gt;&amp;lt;/html&gt;     &lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4119813393983118688?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4119813393983118688/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4119813393983118688' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4119813393983118688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4119813393983118688'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/template-in-webapp.html' title='template in webapp'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5858463502231617184</id><published>2008-08-26T08:59:00.000-07:00</published><updated>2008-09-04T22:01:09.960-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>datastore api</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define a model &amp;amp; create an entity&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;example :&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;# import db &amp;amp; users&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext import db&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.api import users&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;# define a model, inherit from db.Model&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;class Pet(db.Model):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  name = db.StringProperty(required=True)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  type = db.StringProperty(required=True, choices=set(["cat", "dog", "bird"]))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  birthdate = db.DateProperty()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  weight_in_pounds = db.IntegerProperty()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  spayed_or_neutered = db.BooleanProperty()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  owner = db.UserProperty()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;# create an entity&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;pet = Pet(name="Fluffy",&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;          type="cat",&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;          owner=users.get_current_user())&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;pet.weight_in_pounds = 24&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 255);"&gt;# store the entity&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;pet.put()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;_____________________________________________________________&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;get entity from datastore&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. using db.GqlQuery&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;user_pets = db.GqlQuery("SELECT * FROM Pet WHERE pet.owner = :1",&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;                          users.get_current_user())&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;db's property:&lt;/div&gt;&lt;div&gt;1. db.StringProperty&lt;/div&gt;&lt;div&gt;2.db.DateProperty&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;import cgi&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext import db&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext import webapp&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext.webapp.util import run_wsgi_app&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.api import users&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;class Greeting(db.Model):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  author = db.UserProperty()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  content = db.StringProperty(multiline=True)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  date = db.DateTimeProperty(auto_now_add=True)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;class MainPage(webapp.RequestHandler):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def get(self):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write('&amp;lt;html&gt;&amp;lt;body&gt;')&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;for greeting in greetings:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;if greeting.author:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write('&amp;lt;b&gt;%s&amp;lt;/b&gt; wrote:' % greeting.author.nickname())&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;else:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write('An anonymous person wrote:')&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write('&amp;lt;blockquote&gt;%s&amp;lt;/blockquote&gt;' %&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;                              cgi.escape(greeting.content))&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;    # Write the submission form and the footer of the page&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write("""&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;          &amp;lt;form action="/sign" method="post"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;            &amp;lt;div&gt;&amp;lt;textarea name="content" rows="3" cols="60"&gt;&amp;lt;/textarea&gt;&amp;lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;            &amp;lt;div&gt;&amp;lt;input type="submit" value="Sign Guestbook"&gt;&amp;lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;          &amp;lt;/form&gt; &amp;lt;/body&gt;&amp;lt;/html&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;      """)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;class Guestbook(webapp.RequestHandler):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def post(self):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; greeting = Greeting()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; if users.get_current_user():&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;greeting.author = users.get_current_user()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;greeting.content = self.request.get('content')&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;greeting.put()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.redirect('/')&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;application = webapp.WSGIApplication( [('/', MainPage), ('/sign', Guestbook)], debug=True)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def main():&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  run_wsgi_app(application)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;if __name__ == "__main__":&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;     main()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;get data from datastore:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 1:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")  &lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 2:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Greeting.gql("ORDER BY date DESC LIMIT 10")&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 3:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Greeting.gql("WHERE author = :1 ORDER BY date DESC",&lt;/div&gt;&lt;div&gt;                               users.get_current_user())&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 4:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Greeting.gql("WHERE author = :author ORDER BY date DESC",&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;                               author=users.get_current_user())&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 5&lt;/span&gt;:&lt;/div&gt;&lt;div&gt;&lt;div&gt;greetings = Greeting.all()&lt;/div&gt;&lt;div&gt;greetings.filter("author =", users.get_current_user())&lt;/div&gt;&lt;div&gt;greetings.order("-date")&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Clearing the Development Server Datastore&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;dev_appserver.py --clear_datastore helloworld/&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5858463502231617184?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5858463502231617184/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5858463502231617184' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5858463502231617184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5858463502231617184'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/datastore.html' title='datastore api'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3117383940374665902</id><published>2008-08-26T07:40:00.000-07:00</published><updated>2008-08-26T07:47:22.328-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>form in webapp</title><content type='html'>&lt;div&gt;&lt;div&gt;import cgi&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;from google.appengine.ext import webapp&lt;/div&gt;&lt;div&gt;from google.appengine.ext.webapp.util import run_wsgi_app&lt;/div&gt;&lt;div&gt;from google.appengine.api import users&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;class MainPage(webapp.RequestHandler):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;def get(self):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;self.response.out.write("""&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;      &amp;lt;html&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;        &amp;lt;body&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;          &amp;lt;form action="/sign" method="post"&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;            &amp;lt;div&gt;&amp;lt;textarea name="content" rows="3" cols="60"&gt;&amp;lt;/textarea&gt;&amp;lt;/div&gt;&lt;/div&gt;&lt;div&gt;&amp;lt;input type="submit" value="Sign Guestbook"&gt;&amp;lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;          &amp;lt;/form&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;        &amp;lt;/body&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;      &amp;lt;/html&gt;""")&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;class Guestbook(webapp.RequestHandler):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;def post(self):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; self.response.out.write('&amp;lt;html&gt;&amp;lt;body&gt;You wrote:&amp;lt;pre&gt;')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; self.response.out.write(cgi.escape(self.request.get('content')))&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt; self.response.out.write('&amp;lt;/pre&gt;&amp;lt;/body&gt;&amp;lt;/html&gt;')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;application = webapp.WSGIApplication( [('/', MainPage), ('/sign', Guestbook)], debug=True)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;def main():&lt;/div&gt;&lt;div&gt;  run_wsgi_app(application)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if __name__ == "__main__":&lt;/div&gt;&lt;div&gt;  main()&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3117383940374665902?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3117383940374665902/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3117383940374665902' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3117383940374665902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3117383940374665902'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/form-in-webapp.html' title='form in webapp'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-7929525963033243992</id><published>2008-08-26T07:29:00.001-07:00</published><updated>2008-08-26T07:42:47.832-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>users service</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext import webapp&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.ext.webapp.util import run_wsgi_app&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;from google.appengine.api import users&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;class MainPage(webapp.RequestHandler):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def get(self):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;user = users.get_current_user()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;if user:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.headers['Content-Type'] = 'text/plain'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.response.out.write('Hello, ' + user.ni&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;ckname())&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;else:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;self.redirect(users.create_login_url(self.request.uri))&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;application = webapp.WSGIApplication( [('/', MainPage)], debug=True)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;def main():&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  run_wsgi_app(application)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;if __name__ == "__main__":&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  main()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;self.request.uri is current uri. Hence, after successful login, user can back here&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-7929525963033243992?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/7929525963033243992/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=7929525963033243992' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7929525963033243992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7929525963033243992'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/users-service.html' title='users service'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-1643482301270712839</id><published>2008-08-26T07:23:00.000-07:00</published><updated>2008-08-26T07:24:17.332-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>webapp framework</title><content type='html'>&lt;div&gt;from google.appengine.ext import webapp&lt;/div&gt;&lt;div&gt;from google.appengine.ext.webapp.util import run_wsgi_app&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;class MainPage(webapp.RequestHandler):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;def get(self):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;self.response.headers['Content-Type'] = 'text/plain'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;self.response.out.write('Hello, webapp World!')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;application = webapp.WSGIApplication( [('/', MainPage)], debug=True)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;def main():&lt;/div&gt;&lt;div&gt;  run_wsgi_app(application)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if __name__ == "__main__":&lt;/div&gt;&lt;div&gt;  main()&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-1643482301270712839?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/1643482301270712839/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=1643482301270712839' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1643482301270712839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1643482301270712839'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/webapp-framework.html' title='webapp framework'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-8821299655953961657</id><published>2008-08-26T07:02:00.000-07:00</published><updated>2009-01-06T10:09:54.325-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google app engine'/><title type='text'>a hello world page</title><content type='html'>&lt;span class="Apple-style-span"&gt;&lt;span style="font-weight: bold;"&gt;1. create project directory:&lt;/span&gt;&lt;br /&gt;  helloworld&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. in the directory, create two files&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;(1)helloworld.py:&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span style="color: rgb(255, 102, 0);"&gt;print 'Content-Type: text/plain'&lt;/span&gt;&lt;div style="color: rgb(255, 102, 0);"&gt;print ''&lt;/div&gt;&lt;div style="color: rgb(255, 102, 0);"&gt;print 'Hello, world!'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;(2)app.yaml&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;application: helloworld&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;version: 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;runtime: python&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;api_version: 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;handlers:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;- url: /.*&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;  script: helloworld.py&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;url: /.*  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;script: helloworld.py means any url will be handled by helloworld.py&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;(3)run web server:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;dev_appserver.py  helloworld&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(4) connect to server&lt;/span&gt;&lt;br /&gt;127.0.0.1:8080&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(5) update to google web server:&lt;/span&gt;&lt;br /&gt;appcfg.py  helloworld&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-8821299655953961657?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/8821299655953961657/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=8821299655953961657' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8821299655953961657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8821299655953961657'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/hello-world-page.html' title='a hello world page'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4750347381675402230</id><published>2008-08-13T22:33:00.000-07:00</published><updated>2008-08-13T22:35:41.138-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python software'/><title type='text'>development python on eclipse</title><content type='html'>pydev:&lt;div&gt;add " &lt;span class="Apple-style-span" style="color: rgb(37, 32, 32); font-family: Arial; "&gt;&lt;a href="http://pydev.sourceforge.net/updates/" style="text-decoration: underline; "&gt;http://pydev.sourceforge.net/updates/&lt;/a&gt; " on eclipse's software update&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4750347381675402230?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4750347381675402230/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4750347381675402230' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4750347381675402230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4750347381675402230'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/08/development-python-on-eclipse.html' title='development python on eclipse'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4725582829841601729</id><published>2008-07-29T09:13:00.000-07:00</published><updated>2008-07-29T09:14:16.342-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>python imaging library</title><content type='html'>If model in Django wants to use ImageField,  we must install python imaging library&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4725582829841601729?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4725582829841601729/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4725582829841601729' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4725582829841601729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4725582829841601729'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/python-imaging-library.html' title='python imaging library'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-8211410168162953071</id><published>2008-07-25T08:09:00.000-07:00</published><updated>2008-07-25T09:01:35.862-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django view'/><title type='text'>template</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt; template object &amp;amp; context object:&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;from django.template import Template, Context&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a=Template("&amp;lt;p&gt;hello {{name}} &amp;lt;/p&gt;")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b=Context({ 'name': 'Peter' } )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a.render(b)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;{{ }} in template define the variable&lt;/div&gt;&lt;div&gt;context is a dictionary that map variable to value&lt;/div&gt;&lt;div&gt;render function replace the value with value&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;call method in {{ }}:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;no () &amp;amp; no arguments&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{{ dog.bark }}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;list in {{}}:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{{items.2}}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;dictionary in {{}}:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{{ Person.name }}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;define a method that can not be executed by template&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test(self):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;       hello&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test.alters_data=true&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;template tag:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;if &amp;amp; else:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{% if isHot %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     {{isHot}}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{% else %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     not Hot&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;{% endif %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;and ,  or, not,  can be used in if &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{% for  name in nameList %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;       {{ name}}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{% endfor %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for &amp;amp; reverse:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{% for name in nameList reversed %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;     {{name}}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{% endfor %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;forloop.counter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the number of times the loop has been entered&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;forloop.first:&lt;/div&gt;&lt;div&gt;forloop.revcounter:&lt;/div&gt;&lt;div&gt;forloop.last:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;forloop.parentloop:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;reference to the forloop object for the parent loop&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ifequal / ifnotequal:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{%  ifequal a b %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;     test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{%  endifequal %}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;comment:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{#  this is a comment #}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;filter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;change variable,  use | with filter name&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;date filter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 102, 0);"&gt;{{ tempDate | date: "F j, Y" }}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-8211410168162953071?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/8211410168162953071/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=8211410168162953071' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8211410168162953071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8211410168162953071'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/template.html' title='template'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-2999301683798027772</id><published>2008-07-18T08:18:00.000-07:00</published><updated>2008-07-18T08:30:12.564-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>exception</title><content type='html'>ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;ckass Bad(Exception):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;          pass&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def test():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;      raise  Bad(), "test bad"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;try:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;    test()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;except  Bad, info:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     print "bad", info&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;else:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;    print "else"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;finally:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     print "finally"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;assert:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;raise AssertionError when test evaluates to false&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;assert  x&lt;=3, 'x must be larger than 3'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;raise:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex1: raise object&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;class A:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     pass&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     raise A()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex2:  raise string&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;message="Error"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def test():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;      raise  message&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-2999301683798027772?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/2999301683798027772/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=2999301683798027772' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2999301683798027772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2999301683798027772'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/exception.html' title='exception'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-1546274483599622299</id><published>2008-07-14T08:11:00.001-07:00</published><updated>2008-07-14T08:11:46.426-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django general'/><title type='text'>debug in django</title><content type='html'>use &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;assert False&lt;/span&gt;:&lt;div&gt;trigger debug page&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-1546274483599622299?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/1546274483599622299/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=1546274483599622299' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1546274483599622299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1546274483599622299'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/debug-in-django.html' title='debug in django'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-2710125738365059334</id><published>2008-07-14T07:58:00.000-07:00</published><updated>2008-08-14T20:23:05.552-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>change type</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;int:&lt;/span&gt;&lt;div&gt;string to int&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;str:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;int to string&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-2710125738365059334?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/2710125738365059334/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=2710125738365059334' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2710125738365059334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2710125738365059334'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/change-type.html' title='change type'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-858392509925760155</id><published>2008-07-14T07:53:00.000-07:00</published><updated>2008-07-14T07:58:27.151-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django view'/><title type='text'>view function</title><content type='html'>&lt;div&gt;first parameter must be HttpRequest&lt;/div&gt;&lt;div&gt;the other parameters are the string matched by ( ) of urlpatterns&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def hours_ahead(request, offset):&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;offset=int(offset)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;dt= datetime.datetime.now()+ datetime.timedelta(hours=offset)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0); white-space: pre;"&gt;     html="&amp;lt;html&gt;&amp;lt;body&gt;In %s hours(s), it will be %s.&amp;lt;/body&gt;&amp;lt;/html&gt;"% (offset,dt)&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;return HttpResponse(html)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-858392509925760155?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/858392509925760155/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=858392509925760155' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/858392509925760155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/858392509925760155'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/view-function.html' title='view function'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3859182778059892626</id><published>2008-07-13T10:36:00.001-07:00</published><updated>2008-07-14T07:06:50.106-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>class method  &amp; static method</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;class method:&lt;/span&gt;&lt;/div&gt;ex:&lt;div&gt;def  test(cls):&lt;/div&gt;&lt;div&gt;       print('class method')&lt;/div&gt;&lt;div&gt;test=classmethod(test)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;static method:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;def  test()&lt;/div&gt;&lt;div&gt;      print('static method')&lt;/div&gt;&lt;div&gt;test=staticmethod(test)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3859182778059892626?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3859182778059892626/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3859182778059892626' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3859182778059892626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3859182778059892626'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/class-method.html' title='class method  &amp; static method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-7614074376472440719</id><published>2008-07-13T07:50:00.000-07:00</published><updated>2008-07-13T08:01:05.259-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django routing'/><title type='text'>url mapping</title><content type='html'>settings.py has a variable  &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ROOT_URLCONF&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ROOT_URLCONF  decides the python file for routing&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ROOT_URLCONF is urls.py by default&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;when a request comes in, Django loads ROOT_URLCONF and find the match between request url &amp;amp; &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;urlpatterns &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;when pattern found, the associated view function is called( the function is passed HttpRequest object as first parameter) &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the view function will return an HttpResponse object&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define urlpatterns&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;urlpatterns = patterns( '', ( r'^test/$',  testFunction) )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;match  /test/ ,  if request is /test/,  testFunction is called&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define view function:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def test(request):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;now=datetime.datetime.now()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;html= "&amp;lt;html&gt;&amp;lt;body&gt;It is now %s.&amp;lt;/body&gt;&amp;lt;/html&gt;" % now&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;return HttpResponse(html)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-7614074376472440719?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/7614074376472440719/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=7614074376472440719' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7614074376472440719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7614074376472440719'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/url-mapping.html' title='url mapping'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-9016440474785696362</id><published>2008-07-13T07:41:00.000-07:00</published><updated>2008-07-13T07:44:13.362-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>raw string</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;using r:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;turn off escpate&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;tempStr=  r'C:\test'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-9016440474785696362?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/9016440474785696362/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=9016440474785696362' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/9016440474785696362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/9016440474785696362'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/raw-string.html' title='raw string'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-6187650508750231407</id><published>2008-07-13T06:47:00.000-07:00</published><updated>2008-07-13T06:48:25.351-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>python path</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;print python path:&lt;/span&gt;&lt;div&gt;import sys&lt;/div&gt;&lt;div&gt;print  sys.path&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-6187650508750231407?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/6187650508750231407/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=6187650508750231407' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6187650508750231407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6187650508750231407'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/python-path.html' title='python path'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-6584309831711905711</id><published>2008-07-13T05:58:00.001-07:00</published><updated>2008-07-29T08:38:26.233-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django general'/><title type='text'>create a project, create an app, run the server,  path, timezone</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;create a projct&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;django-admin.py  startproject  newSite&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;create an app in the project:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0); "&gt;python manage.py   startapp books&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;create  __init__.py, models.py,  views.py in books directory &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;run the server:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;python manage.py   runserver&lt;/span&gt;&lt;/div&gt;&lt;div&gt;running at 127.0.0.0.1:8000&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;python manage.py  runserver  0.0.0.0  8888&lt;/span&gt;&lt;/div&gt;&lt;div&gt;listen on any network interface,  on port 8888&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;set path for django project&lt;/span&gt;&lt;/div&gt;&lt;div&gt;add django_site.pth  under /Library/Python/2.5/site-packages&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;django_site.pth:&lt;/div&gt;&lt;div&gt;/Volumes/Data/django_project/&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;time zone&lt;/span&gt;&lt;/div&gt;&lt;div&gt;in settings.py&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;TIME_ZONE = 'Asia/Taipei'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-6584309831711905711?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/6584309831711905711/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=6584309831711905711' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6584309831711905711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6584309831711905711'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/create-project.html' title='create a project, create an app, run the server,  path, timezone'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4168951548052577425</id><published>2008-07-13T05:52:00.000-07:00</published><updated>2008-07-13T05:53:29.688-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django general'/><title type='text'>install django</title><content type='html'>sudo python setup.py install&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4168951548052577425?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4168951548052577425/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4168951548052577425' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4168951548052577425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4168951548052577425'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/install-django.html' title='install django'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-2411872260340272824</id><published>2008-07-13T05:46:00.000-07:00</published><updated>2008-07-13T05:49:20.012-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>__name__  &amp; __main__</title><content type='html'>when the file is run as a top-level program,  __name__ is set as __main__&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;when the file is imported,  __name__ is set to the module's name&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hence, we can use __name__ to do unit test.&lt;/div&gt;&lt;div&gt;If  __name__ == __main__,   we execute unit test&lt;/div&gt;&lt;div&gt;if __name__ != __main__,  unit test is not executed &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-2411872260340272824?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/2411872260340272824/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=2411872260340272824' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2411872260340272824'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/2411872260340272824'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/07/name-main.html' title='__name__  &amp; __main__'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-6910761557330393555</id><published>2008-06-26T22:07:00.000-07:00</published><updated>2008-07-13T06:40:01.490-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>module</title><content type='html'>a python file is a module&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;use import to import module:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import  test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;this will import test.py&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;a module is imported only once per process by default. Further imports reuse loaded modules in memory&lt;/div&gt;&lt;div&gt;use sys.modules.keys() to find loaded module&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;when module is imported, the module is executed&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;module search path:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;import modules in other directories:&lt;/div&gt;&lt;div&gt;set PHTYONPATH&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import and from:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. only use import:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test.run()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. use import and from&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;from test import run&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;run()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;now we can reference run() without test&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;from test import *&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;now we can reference any attribute of module test&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;show module's attribute&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test.__dict__.keys()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;reload:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;reload(test)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;module packages:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import  dir1.dir2.test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;dir1 and dir2 are directories,  the file imported is test.py&lt;/div&gt;&lt;div&gt;dir1 and dir2 must both contain  __init__.py&lt;/div&gt;&lt;div&gt;dir1 must under the directory of python search path&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-6910761557330393555?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/6910761557330393555/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=6910761557330393555' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6910761557330393555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/6910761557330393555'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/module.html' title='module'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-7835880572438461377</id><published>2008-06-23T22:00:00.000-07:00</published><updated>2008-06-23T22:07:14.066-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>loop</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;while  ... else...&lt;/span&gt;&lt;div&gt;the else is executed if break is not excuted in the while&lt;br /&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;while  x&gt; 1:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;          if  x&gt;10&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;              break&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;        print  x&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;for ...  else  is the same as while ...  else ...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;for applies to list, string , tuple&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-7835880572438461377?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/7835880572438461377/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=7835880572438461377' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7835880572438461377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7835880572438461377'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/loop.html' title='loop'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4794601624661077657</id><published>2008-06-23T03:58:00.000-07:00</published><updated>2008-06-23T04:00:14.307-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>lambda</title><content type='html'>ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;f= lambda x, y: x+y&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;f(1,2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  3&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4794601624661077657?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4794601624661077657/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4794601624661077657' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4794601624661077657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4794601624661077657'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/lambda.html' title='lambda'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-8608468508100204197</id><published>2008-06-20T18:19:00.001-07:00</published><updated>2008-06-20T18:28:47.715-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>define class</title><content type='html'>&lt;div&gt;ex:&lt;/div&gt;class Test:&lt;div&gt;     def  __init__(self, name):&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;     self.name=name&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;      def  hello(self):&lt;/div&gt;&lt;div&gt;             return  "hello"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;t= Test("peter")&lt;/div&gt;&lt;div&gt;t.name&lt;/div&gt;&lt;div&gt;---&gt; "peter"&lt;/div&gt;&lt;div&gt;t.hello&lt;/div&gt;&lt;div&gt;---&gt; "hello"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-8608468508100204197?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/8608468508100204197/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=8608468508100204197' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8608468508100204197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/8608468508100204197'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/define-class.html' title='define class'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4452273809004782864</id><published>2008-06-20T18:08:00.000-07:00</published><updated>2008-06-20T18:11:02.655-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>set</title><content type='html'>a=set('abcd')&lt;div&gt;b=set('cdef')&lt;/div&gt;&lt;div&gt;a | b&lt;/div&gt;&lt;div&gt;---&gt; set(['a', 'b', 'c', 'd', 'e',  'f'] )&lt;/div&gt;&lt;div&gt;a &amp;amp; b&lt;/div&gt;&lt;div&gt;---&gt;   set( [ 'c', 'd' ] )&lt;/div&gt;&lt;div&gt;a - b&lt;/div&gt;&lt;div&gt;---&gt;  set( [ 'a', 'b' ] )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4452273809004782864?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4452273809004782864/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4452273809004782864' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4452273809004782864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4452273809004782864'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/set.html' title='set'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-1277076562934777190</id><published>2008-06-20T18:05:00.000-07:00</published><updated>2008-06-20T18:07:52.148-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>file methods</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;open:&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;open('test.txt', 'w')&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;read:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;return entire file into string&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-1277076562934777190?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/1277076562934777190/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=1277076562934777190' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1277076562934777190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1277076562934777190'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/file-methods.html' title='file methods'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-127493318839127739</id><published>2008-06-20T17:53:00.001-07:00</published><updated>2008-06-20T18:18:28.097-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>sorted,  type</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sorted&lt;/span&gt;&lt;/div&gt;ex:&lt;div&gt;sorted([2,1])&lt;/div&gt;&lt;div&gt;---&gt;  [1,2]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;type:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;know the object's type&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;type("test")&lt;/div&gt;&lt;div&gt;---&gt;  &amp;lt;type , 'str'&gt; &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;check type methods:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;(1) if type(a) ==type([]):&lt;/div&gt;&lt;div&gt;(2) if type(a)== list:&lt;/div&gt;&lt;div&gt;(3) if  isinstance(a, list):&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-127493318839127739?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/127493318839127739/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=127493318839127739' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/127493318839127739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/127493318839127739'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/sorted.html' title='sorted,  type'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-7100958604589074863</id><published>2008-06-20T17:43:00.000-07:00</published><updated>2008-06-20T17:46:28.564-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>for</title><content type='html'>ex:&lt;div&gt;for a in [1,2,3]:&lt;/div&gt;&lt;div&gt;    print  a&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-7100958604589074863?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/7100958604589074863/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=7100958604589074863' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7100958604589074863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/7100958604589074863'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/for.html' title='for'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3352889008323654957</id><published>2008-06-20T17:18:00.000-07:00</published><updated>2008-07-25T08:30:39.130-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>dictionary</title><content type='html'>use  {  }&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test= { "a":"peter",  "b":"andy" }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt; test["a"]="peter"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;keys:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;has_key:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;delete an element in dictionary:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a={ 'age':3  }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;del  a['age']&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3352889008323654957?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3352889008323654957/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3352889008323654957' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3352889008323654957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3352889008323654957'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/dictionary.html' title='dictionary'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4071688050965013278</id><published>2008-06-20T09:41:00.000-07:00</published><updated>2008-07-13T10:11:16.134-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>regular expression</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;match&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import re&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;match= re.match( '/(.*)/(.*)', 'abc/def/' )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;match.groups()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt; ( 'abc', 'def' )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;^:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;match the start of  the string&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;$:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;match the end of the string&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;{ }:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;\d{1,2}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;one or two numbers&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4071688050965013278?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4071688050965013278/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4071688050965013278' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4071688050965013278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4071688050965013278'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/regular-expression.html' title='regular expression'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4041807031995100918</id><published>2008-06-20T09:20:00.000-07:00</published><updated>2008-07-14T08:02:03.787-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>string method</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;find:&lt;/span&gt;&lt;div&gt;return the offset of argument&lt;br /&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;'test'.find('es')&lt;/div&gt;&lt;div&gt;---&gt;  1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;replace:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a='test'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a.replace('t' , 'b')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  a is 'best'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;split:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;'aaa,bbb'.split(',')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; [ 'aaa', 'bbb' ]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;upper:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;'test'.upper()&lt;/div&gt;&lt;div&gt;---&gt;  'TEST'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;isalpha(),  isdigit()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;rstripe()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;remove whitespace on the right side&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ord&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;ord('a')&lt;/div&gt;&lt;div&gt;--&gt; 97&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;""":&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a= """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;  ""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;c&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;"""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;print a&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;   b &lt;/div&gt;&lt;div&gt;             ""&lt;/div&gt;&lt;div&gt;          c&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;format string:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;n1=1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;n2=2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;print (" num1 %d num2 %d"  %(n1, n2) )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4041807031995100918?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4041807031995100918/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4041807031995100918' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4041807031995100918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4041807031995100918'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/string-method.html' title='string method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-1930849677309579073</id><published>2008-06-20T09:17:00.000-07:00</published><updated>2008-06-20T09:18:53.568-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>immutable object &amp; mutable object</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;immutable object:&lt;/span&gt;&lt;div&gt;number,  string, tuple&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;mutable object:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;list , dictionary &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-1930849677309579073?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/1930849677309579073/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=1930849677309579073' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1930849677309579073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/1930849677309579073'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/immutable-object-mutable-object.html' title='immutable object &amp; mutable object'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3193527436345236856</id><published>2008-06-20T09:12:00.000-07:00</published><updated>2008-06-23T03:19:23.027-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>slicing</title><content type='html'>&lt;div&gt;apply to string, list&lt;/div&gt;&lt;div&gt;return a new string or list&lt;/div&gt;ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a="test"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a[1:3]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  es&lt;/div&gt;&lt;div&gt;( offset 1 to 2, not including 3)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a[1:]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt;  est&lt;/div&gt;&lt;div&gt;( left offset defaults to the length of a)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a[:3]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; tes&lt;/div&gt;&lt;div&gt;(right offset defaults to 0)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3193527436345236856?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3193527436345236856/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3193527436345236856' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3193527436345236856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3193527436345236856'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/slicing.html' title='slicing'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3841984776492850096</id><published>2008-06-20T09:02:00.000-07:00</published><updated>2008-06-20T09:04:55.915-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>== &amp; is</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;==:&lt;/span&gt;&lt;div&gt;compare value of  two object&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;is:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;compare if two variables point to the same object&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;if a is b&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3841984776492850096?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3841984776492850096/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3841984776492850096' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3841984776492850096'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3841984776492850096'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/is.html' title='== &amp; is'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4191784811727283808</id><published>2008-06-20T08:57:00.000-07:00</published><updated>2008-06-23T03:42:59.058-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>in-place changes &amp; non in-place changes</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;non in-place change:&lt;/span&gt;&lt;div&gt;for immutable object, such as number &amp;amp; string&lt;br /&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a=3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b=a&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b=2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  a=3 ,  b=2&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;in-place  changes:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;for list , dictionary , etc&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a=[1,2,3]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b=a&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b[0]=5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  a=[5,2,3],  b=[5,2,3]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;note:&lt;/div&gt;&lt;div&gt;a=[1,2]&lt;/div&gt;&lt;div&gt;b=a&lt;/div&gt;&lt;div&gt;b=[3,4]&lt;/div&gt;&lt;div&gt;---&gt;  a is still [1,2]  because now  b &amp;amp; a point to different objects&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the parameter of the function is passed by assignment &lt;/div&gt;&lt;div&gt;Hence, it is the same.&lt;/div&gt;&lt;div&gt;If parameter is mutable, it can be changed&lt;/div&gt;&lt;div&gt;If parameter is not mutable, it can not be changed&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;how to change non-mutable argument for caller:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;using return value&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;def  test(x, y)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     x=3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     y= 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     return x, y&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a=2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;b=2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a, b= test(a, b)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4191784811727283808?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4191784811727283808/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4191784811727283808' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4191784811727283808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4191784811727283808'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/in-place-changes-non-in-place-changes.html' title='in-place changes &amp; non in-place changes'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-5686626178115535911</id><published>2008-06-20T08:51:00.000-07:00</published><updated>2008-06-20T17:56:17.511-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>list  and tuple</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;list:&lt;/span&gt;&lt;/div&gt;using []&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a=[1,2,3]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;+:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;[1,2] +[3,4]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; [1,2,3,4]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sort()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;reverse()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;get column from list:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a=[ [1,2], [3,4] ]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;b=[ row[1] for row in a]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; b= [2,4]&lt;/div&gt;&lt;div&gt;row[1] means second column&lt;/div&gt;&lt;div&gt;Hence, second column for each row&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;append:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;tuple:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use ()&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;a= (1,2,3)&lt;/div&gt;&lt;div&gt;It is like list , but it is immutable &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-5686626178115535911?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/5686626178115535911/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=5686626178115535911' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5686626178115535911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/5686626178115535911'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/list.html' title='list  and tuple'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-4529425061321554468</id><published>2008-06-20T07:31:00.000-07:00</published><updated>2008-06-20T09:32:05.983-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>dir &amp; help</title><content type='html'>dir( module_name):&lt;div&gt;return all attributes inside that module&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;dir( "test")&lt;/div&gt;&lt;div&gt;--&gt; string's attribute, such as string's methods&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;help:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;find info about API&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;help("test".index)&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-4529425061321554468?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/4529425061321554468/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=4529425061321554468' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4529425061321554468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/4529425061321554468'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/dir.html' title='dir &amp; help'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3556079530017217479</id><published>2008-06-20T07:23:00.001-07:00</published><updated>2008-06-20T07:23:37.004-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>define method</title><content type='html'>def  test( arg1 ):&lt;div&gt;        print "hello"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3556079530017217479?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3556079530017217479/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3556079530017217479' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3556079530017217479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3556079530017217479'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/define-method.html' title='define method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3967080224183399920.post-3090623158750387683</id><published>2008-06-20T07:06:00.000-07:00</published><updated>2008-06-23T03:55:27.115-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python general'/><title type='text'>variable in the function</title><content type='html'>when assign a name A in a function, it will create a local variable a&lt;div&gt;In the function, we can read the value of global variable A&lt;/div&gt;&lt;div&gt;However, if you want to modify global variable A, you must using following methods:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;global:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use global to modify global variable&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;x=1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test():&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;      global  x&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;      x=3&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;access attribute in other module:&lt;/div&gt;&lt;div&gt;using import&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;import  test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test.var = 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;nested function:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def test:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;    x=3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;    def  test2:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;        print x&lt;/span&gt;&lt;/div&gt;&lt;div&gt;test2 can access x defined in test &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;keyword parameter&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test(a, b):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;        print  a, b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test( a=3, b=2)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;default parameter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test(a, b=3):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;       printf  a, b&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test( 2)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;arbitrary argument:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test(*args):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;       print args&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test( 1,2,3)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;** is for keyboard argument&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;def  test(**args):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;      print  args&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test(a=1,b=2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;use * in caller:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;unpack a collection of arguments&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;a= (1,2,3,4)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 153, 0);"&gt;test( *a)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;use ** in caller:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;unpack a dictionary of key/value pairs&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3967080224183399920-3090623158750387683?l=deeplylovepython.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplylovepython.blogspot.com/feeds/3090623158750387683/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3967080224183399920&amp;postID=3090623158750387683' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3090623158750387683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3967080224183399920/posts/default/3090623158750387683'/><link rel='alternate' type='text/html' href='http://deeplylovepython.blogspot.com/2008/06/variable-in-function.html' title='variable in the function'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
