中国开发网: 论坛: 程序员情感CBD: 贴子 670229
龙之吻
感谢楼上各位牛的热情解答..我在程序中的路径都编程unicode了,开发机没有问题,到了没有装python的机器,报错的为之是import语句。这个怎么处理?
#!/usr/bin/env python
#coding=utf-8
import os
import codecs
import locale
import types
#def GetCurrDir(): return os.path.dirname("cndevOE.exe")
try:
defaultencoding = locale.getdefaultlocale()[1]
except:
defaultencoding = None

if not defaultencoding:
defaultencoding = 'utf-8'
try:
codecs.lookup(defaultencoding)
except:
defaultencoding = 'utf-8'

try:
defaultfilesystemencoding = sys.getfilesystemencoding()
except:
defaultfilesystemencoding = None

if not defaultfilesystemencoding:
defaultfilesystemencoding = 'ascii'
try:
codecs.lookup(defaultfilesystemencoding)
except:
defaultfilesystemencoding = 'ascii'

def GetCurrDir():
path = os.path.dirname(__file__)
if os.path.isfile(path):
path = os.path.dirname(os.path.abspath(path))
#print decode_string(path)
return decode_string(path)
#return os.path.dirname("cndevOE.exe")
def GetTransforSymbol():
return {"&lt;":"<","&gt;":">","&quot;":'"',"&#40;":"(","&#41;":")","&#32;":" ","&#64;":"@","&amp;":"&"}

def unicode_path(path, encoding=defaultfilesystemencoding):
"""convert path to unicode
"""
return decode_string(path, encoding)

def (path, encoding=defaultfilesystemencoding):
return encode_string(path, encoding)


def decode_string(string, encoding=None):
"""convert string to unicode

If the second parameter encoding is omit, the default locale will be used.
"""
if not encoding:
encoding = defaultencoding
if not isinstance(string, types.UnicodeType):
return unicode(string, encoding)
else:
return string
unicode_string = decode_string

def encode_string(string, encoding=None):
"""convert unicode to string

If the second parameter encoding is omit, the default locale will be used.
"""
if not encoding:
encoding = defaultencoding
if isinstance(string, types.UnicodeType):
return string.encode(encoding)
else:
return string


机器人,这首歌学会了没有?

我们的目标是->没有蛀牙!

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录