Python:Spé;路径名中的字符

Python:Spé;路径名中的字符,python,char,decode,encode,Python,Char,Decode,Encode,我对eventghost中的python脚本有问题:例如globals.test是一个外部变量 eg.globals.test = "test♥.png" 我的脚本: Import Image print eg.globals.test #test♥.png picture = Image.open(eg.globals.test) Python转换♥ 到\u2665.png。我试过编码、解码、unicode函数,但没有效果。你试过在脚本顶部添加#-*-编码:utf-8-*-吗?你试

我对eventghost中的python脚本有问题:
例如globals.test
是一个外部变量

eg.globals.test = "test♥.png"
我的脚本:

Import Image

print eg.globals.test 

#test♥.png

picture = Image.open(eg.globals.test)

Python转换♥ 到
\u2665.png
。我试过编码、解码、unicode函数,但没有效果。

你试过在脚本顶部添加
#-*-编码:utf-8-*-
吗?你试过“编码、解码、unicode函数”,好吧,告诉我们。好吧,文件名上不能有特殊符号…@Kroltan你可以在文件名中有特殊字符。这完全取决于操作系统。有些操作系统允许任何unicode文件名,而另一些操作系统则非常严格。知道OP运行的是哪一个操作系统可能会有所帮助……嗯,的确如此,但一般来说,跨平台代码(比如Python是Classicali)应该尽可能地同质化。我建议OP坚持使用
a-z
a-z
0-9
-
,因为所有操作系统都支持这些功能。至于问题本身,我无能为力。。。
# IOError: [Errno 2] No such file or directory: test \u2665.png'