顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2015/10/01

Install Python 3 on Mac OSX

I have installed Python 2.x on Mac OSX. The detailed please refer to this link. However I also need to learn Python 3.x on Mac OSX. So I find the way to install Python 3.x on Mac OSX.

2015/09/10

Python Chinese String Index Usage 中文字串

我在《Python String List Chinese Encode Decode 中文編碼解碼》一文介紹了 Python 中文 String 和 List 的編碼和解碼方法。

在本文裏,我們利用以下兩種方式使用 [] 指定索引來取得字串中的某個字元:
  • 直接印出宣告 Unicode 的特定字串
  • 使用 unicode 的 .encode 函數以 UTF-8 編碼 String 印出

但要特別注意 Python2 和 Python3 在 Unicode 上的重要差別:
在Python3因為字串已經全部統一成 unicode ,所以不必加上 u ,這是Python2和Python3的重要差別之一,需要特別注意

2015/08/11

Python String List Chinese Encode Decode 中文編碼解碼

最近要在 Python 內使用中文,就開始研究顯示中文的方法。

在 Python 內設計 Unicode 這個超級容器物件,能用來顯示各類、各樣的字元。同時,Unicode 物件也是一個萬用編碼器,只要善用這個物件的能力,就能解決轉碼問題。

2015/08/06

Python Property Setter Getter TypeError int

以前寫 Java 的時候,需要寫 getX() 以及 setX(),但最近在學習 Python 時才知道 pythonic 方式可以直接使用 property 就可以達到 getter 以及 setter 效果。

只是我使用 property 的 Setter 遇到了以下問題,就把整個過程記錄下來提供其他人做參考。
TypeError: 'int' object is not callable

但在 Python 內使用 property 時仍然要注意,在《Python 慣用語 - 14 用 property 取代 getters, setters》裏有提到:
要避免對吃資源的 method 使用 property ,因為存取 attribute 給人的感覺是很輕量的操作,這樣使用該物件的人就有可能忽視效能的問題。

2015/08/03

Python overloading in a function with default arguments

在一般的情況下,Python Function 的 overloading 必須分別寫在同名、但分開描述的 Function 內,但我真的就想要試試寫出在 Pythone 下能在同一 Function 的 overloading。

2014/12/09

Install Python on OSX based on XCode

From the reference, XCode may great for learning but it's not good for development. Since the Python version shipped with XCode may be out of date from the official current Python release.

從參考資料得知,利用 XCode 的方式學習 Python 是不錯的選擇,但因為 XCode 不一定會使用最新版的 Python,所以不利於開發。

You might use Eclipse to learn Python, but I'm a beginner. Finally I choose XCode 6 + Command Line Tool to learn Python.

我找到的另一種方案是使用 Eclipse,但我只是想學習 Python,最後我仍然選擇 XCode 6 + Command Line Tool 做為我學習 Python 的平台。