1. 程式人生 > >關於Python萬惡的中文亂碼和找不到問題

關於Python萬惡的中文亂碼和找不到問題

color 變現 亂碼 path pat python round unicode 傳遞

rootDir = os.path.join(CASE_PATH, "系統", "基礎", "管理")
print rootDir
print(chardet.detect(rootDir))
print os.path.exists(rootDir)
unicode(rootDir, "utf-8")
print rootDir
print(chardet.detect(rootDir))
print os.path.exists(unicode(rootDir, "utf-8"))

E:\ABS\TestCase\系統\基礎\管理 

{‘confidence‘: 0.99, ‘language‘: ‘‘, ‘encoding‘: ‘utf-8‘}

False

E:\ABS\TestCase\系統\基礎\管理

{‘confidence‘: 0.99, ‘language‘: ‘‘, ‘encoding‘: ‘utf-8‘}

True



網上各種回答亂入:

1.python默認安裝的時候編碼是ASCII

2.python內部執行程序時傳遞時是UNICODE

3.python內存中中文變現為UNNICODE


解決方法如上,暫時還在淩亂,後續再看吧


又報錯打印出來路徑變成16進制了

解決:rootDir.decode(‘utf-8‘).encode(‘utf-8‘)

關於Python萬惡的中文亂碼和找不到問題