NameError: global name 'unicode' is not defined - in Python 3

問題:

I am trying to use a Python package called bidi.我正在嘗試使用名爲 bidi 的 Python 包。 In a module in this package (algorithm.py) there are some lines that give me error, although it is part of the package.在這個包 (algorithm.py) 的一個模塊中,有一些行給我錯誤,儘管它是包的一部分。

Here are the lines:以下是幾行:

# utf-8 ? we need unicode
if isinstance(unicode_or_str, unicode):
    text = unicode_or_str
    decoded = False
else:
    text = unicode_or_str.decode(encoding)
    decoded = True

and here is the error message:這是錯誤消息:

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    bidi_text = get_display(reshaped_text)
  File "C:\Python33\lib\site-packages\python_bidi-0.3.4-py3.3.egg\bidi\algorithm.py",   line 602, in get_display
    if isinstance(unicode_or_str, unicode):
NameError: global name 'unicode' is not defined

How should I re-write this part of the code so it works in Python3?我應該如何重寫這部分代碼以便它在 Python3 中工作? Also if anyone have used bidi package with Python 3 please let me know if they have found similar problems or not.另外,如果有人在 Python 3 中使用過 bidi 包,請告訴我他們是否發現了類似的問題。 I appreciate your help.我感謝您的幫助。


解決方案:

參考一: https://en.stackoom.com/question/1LOzi
參考二: https://stackoom.com/question/1LOzi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章