我有一個名爲hello.txt的沿側test.py本地目錄中的文件,其中包含此的Python 3.4代碼:如何克服的Python 3.4 NameError:名字「即basestring」沒有定義
import easywebdav
webdav = easywebdav.connect('192.168.1.6', username='myUser', password='myPasswd', protocol='http', port=80)
srcDir = "myDir"
webdav.mkdir(srcDir)
webdav.upload("hello.txt", srcDir)
當我運行此我得到這個:
Traceback (most recent call last):
File "./test.py", line 196, in <module>
webdav.upload("hello.txt", srcDir)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/easywebdav/client.py", line 153, in upload
if isinstance(local_path_or_fileobj, basestring):
NameError: name 'basestring' is not defined
谷歌搜索這會導致幾命中,所有這些point到,如果路徑在未來的移動相同的修訂,是包括「導入類型之後「:
try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str,bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring
我沒有使用導入類型,但是包含它或不包含在PyDev中沒有任何區別 - 我無論如何都會遇到錯誤。引起錯誤的行是:
unicode = unicode
說'未定義變量'。
好吧,我的Python知識在這一點上動搖了,我在這個網站上尋找類似的帖子,沒有找到一個足夠的基礎字符串,我明白幫助。我知道我需要指定basestring,但我不知道如何去做。任何人都會有足夠的慈善來指引我走向正確的方向嗎?
您使用的是什麼版本的easywebdav? – ooga 2014-09-30 21:57:24
easywebdav 1.2.0 – volvox 2014-10-01 11:11:15