Recent Comments
Tag cloud
Archives
Categories
Blogroll
Links
Meta
Category Archives: Python
Use VERSIONER_PYTHON_PREFER_32_BIT=yes in Snow Leopard
In python, you can use ctype (dl is deprecated now) to load dynamic link library. In 10.4 and 10.5 it may work fine, but it may occur errors in 10.6, such as /Library/Frameworks/dummy.framework/dummy: no matching architecture in universal wrapper Since … Continue reading
Posted in Programming, Python
Tagged "Snow Leopard", python, VERSIONER_PYTHON_PREFER_32_BIT
Leave a comment
Using minimock for Python unit testing
我也忘了什麼時候開始習慣作 unit testing 了,可能是前一個專案在 Xcode 上就開始學著寫一點測試了。 這次在閱讀 Writing Testable Code 對於 6. Static methods: (or living in a procedural world),格外有感覺。 尤其是修改別人的程式碼的時候,如果他總是直接呼叫 static method,不讓你用 mock object 把 implementation 換掉的話,這樣在測試起來就顯得麻煩的多。舉例來說,有一個 class method 會呼叫 SSHHelper.execute_ssh 這個指令去遠端執行一些東西,但這對 unit testing 而言就是一種外部的 dependency,你絕對不希望他真的在測試的時候跑出個 ssh 真的連過去執行些什麼吧。 剛好這次用 … Continue reading
The global statement in python
寫 code 時候踩到地雷,果然沒唸好 scope 果然是不行的 #!/usr/bin/env python flag = True def test(): flag = False print flag test() print flag 結果似乎和想的不太一樣。 # python 2.py True True 結果翻了一下 The global statement 才知道 It would be impossible to assign to a global … Continue reading
vim 裡的 python autocomplete
把 http://www.vim.org/scripts/script.php?script_id=850 的東西抓回來丟到 .vim 下面,然後按照 readme 的作,之後按 ctrl+n 或者 ctrl+p 就可以看到漂亮的下拉選單了。 強者我同學 Pky 應該會叫我去 http://wiki.python.org/moin/IntegratedDevelopmentEnvironments 找個好用的吧,不過我就是喜歡用 vim 啦~~
Python: range() 與 xrange()
http://docs.python.org/lib/built-in-funcs.html This function is very similar to range(), but returns an “xrange object” instead of a list. This is an opaque sequence type which yields the same values as the corresponding list, without actually storing them all simultaneously. The advantage … Continue reading