十一月 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
指令照打沒效=.=
還是自己作連結比較保險
sudo ln -s /opt/local/bin/python python
Tagged with: cli • osx • Python • tips • Unix-like
十一月 11
進 settings.py 編輯
時區調整
TIME_ZONE = 'Asia/Taipei'
語系調整
LANGUAGE_CODE = 'zh-tw'
Tagged with: Django • Python
十一月 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:
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:
Tagged with: CJKV • Programming • Python • tips • UTF-8
一月 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: Perl • Programming • Python • Ruby
最新回應