[英]TextMate doesn't perform encode() function in python
朋友們。
我處理 TextMate 中的一個問題,我用它來正常編寫代碼。
對於我的 hash map 腳本,我需要將字符串編碼為字節。
例如,如果我寫:
password = "orange"
bytes_list = list(password.encode())
print(bytes_list)
預期的 output 是[111, 114, 97, 110, 103, 101]
如果我從 Python 的 IDLE 運行腳本並且即使我在 shell 中編寫相同的代碼,我也會得到。
但是如果我在 TextMate 中運行代碼,結果會產生['o', 'r', 'a', 'n', 'g', 'e']
,所以很明顯,TextMate 中的encode() function沒有按預期工作。
有趣的是,如果我執行從 TextMate 到 shell 的代碼,它也不起作用。
在 TextMate 的首選項中,編碼設置為Unicode - UTF-8並安裝了 Unicode 包。
我無法通過 Google 找到該主題的任何答案。 也許你們中的一些人過去遇到過這樣的問題。
謝謝你的幫助。
您的 TextMate 正在使用 Python 2.7:
$ python
Python 2.7.16 (default, Dec 3 2019, 07:02:07)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> password = "orange"
>>> bytes_list = list(password.encode())
>>> print(bytes_list)
['o', 'r', 'a', 'n', 'g', 'e']
>>>
Python 3 將給出您期望的 output:
$ python3
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> password = "orange"
>>> bytes_list = list(password.encode())
>>> print(bytes_list)
[111, 114, 97, 110, 103, 101]
>>>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.