Python isalpha()和scandics

use*_*765 2 python string character-encoding

有没有办法让python isalpha方法理解scandics?我尝试过以下方法:

>>> import locale
>>> locale.getlocale()
(None, None)
>>> 'thisistext'.isalpha()
True
>>> 'äöå'.isalpha()
False
>>> locale.setlocale(locale.LC_ALL,"")
'Finnish_Finland.1252'
>>> locale.getlocale()
('Finnish_Finland', '1252')
>>> 'äöå'.isalpha()
False
Run Code Online (Sandbox Code Playgroud)

Ole*_*huk 7

最简单的方法是在你的情况下使用unicode字符串.只需在字符串前加上'u'符号:

>>> u'??????'.isalpha()
True
Run Code Online (Sandbox Code Playgroud)

或者这行作为文件的第一行:

# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)