preload
十一月 12

因為用 Leopard 內建的 Python 在互動模式下中文有問題
所以來用 MacPorts 裝 Python 2.6,裝好之後出現
To fully complete your installation and make python 2.6 the default, please run

sudo port install python_select
sudo python_select python26

python_select:Switch the default python interpreter


指令照打沒效=.=

還是自己作連結比較保險

cd /usr/bin/
sudo ln -s /opt/local/bin/python python
Tagged with:
十一月 11

進 settings.py 編輯

時區調整
TIME_ZONE = 'Asia/Taipei'

語系調整
LANGUAGE_CODE = 'zh-tw'

Tagged with:
十一月 11

安裝

tar zxvf Django-*.tar.gz
cd Django-*.
sudo python setup.py install

開一個新專案

~/djcode$ django-admin.py startproject mysite
~/djcode$ ls -a mysite/
./           ../          __init__.py  manage.py    settings.py  urls.py
    __init__.py: 偽裝目錄成package
    manage.py: 一個cli的工具,讓妳可以用多種方式和Django專案互動
    settings.py: Django專案的設定/組態
    urls.py: 此Django專案的URL宣告

執行開發用Server

~/djcode/mysite$ python manage.py runserver
Validating models...
0 errors found
 
Django version 1.1.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[10/Nov/2009 19:55:59] "GET / HTTP/1.1" 200 2053
It worked!

It worked!

改Port或IP

python manage.py runserver 8080
python manage.py runserver 0.0.0.0:8080
Tagged with:
十一月 05

tchinese.py

#!/bin/python
print "Python是個酷玩意"
python tchinese.py
SyntaxError: Non-ASCII character '\xe6' in file tchinese.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

錯誤訊息中的連結到這篇文章:PEP 0263 — Defining Python Source Code Encodings
文中提到:

To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:

# coding=<encoding name>

or (using formats recognized by popular editors)

#!/usr/bin/python
# -*- coding: <encoding name> -*-

or

#!/usr/bin/python
# vim: set fileencoding=<encoding name> :

Example:

#!/bin/python
# -*- coding: utf-8 -*-
print "Python是個酷玩意"

Result:

Python是個酷玩意
Tagged with:
十一月 02
這是一本不錯的 Python 工具書,適合 Python 初學者閱讀的入門書
中譯版

電腦做什麼事是一系列Python程式語言的教學文章,我們嘗試提供給讀者以簡單、直覺的方式學習程式語言,進而了解體會電腦背後運作的道理。

來源:學習寫程式 – Sy3es_wiki

Tagged with:
一月 14

剛找了一下這三種動態語言的比較,來小小整理一下。

Perl


Perl 語言的中心思想可以集成為一句話「TMTOWTDI」:

There’s More Than One Way To Do It.
(不只一種方法來做這件事。)

Perl 的作者 Larry Wall 建議可以把這個縮寫詞念成「Tim Toady」。

另一個常常讓人想起的 Perl 俗語是:

Easy things should be easy, and hard things should be possible.

Python


Python 發明人 Tim Peters 寫的 python 格言(稱為The Zen of Python)道:

There should be one– and preferably only one –obvious way to do it.

Ruby


KISS原則(Keep It Super Simple)

POLS原則(最小驚訝原則):Principle Of Least Surprise

參考資料1:人蔘劇場 – Ruby,Python,Perl 中心思想的不同
參考資料2:Lighty RoR: Ruby 跟 Python 本質上不同

參考資料3:INET6: 先天與後天程式語言風格

Tagged with: