今天我遇到了一個奇怪的問題。我使用Python標準庫的string
模塊的letters
變量,並注意到bpython中的結果與香草python中的結果不同。爲什麼python和bpython之間的string.letters不同?
我使用Python 2.7.3和bpython 0.10.1和virtualenv 1.8.4。這是我所看到的。
$ bpython
>>> import string
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
$ python
>>> import string
>>> string.letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
我不知道它的問題,但我在xubuntu 12.10上運行這個。
有人能解釋一下這裏發生了什麼嗎?
我的猜測是他們只是不同的實現,其中一個說'string.letters = string.ascii_upper + string.ascii_lower',另一個'string.letters = string.ascii_lower + string.ascii_upper',我不認爲它會對你的程序有任何影響(除非你正在嘗試執行'string.letters [:26]'或其他什麼) – 2013-04-24 15:48:10
這很奇怪:使用'string.letters'我得到和你一樣的結果,但是使用'string。 ascii_letters'我在python和bpython中都得到'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ''。 – dusan 2013-04-24 17:16:32