2005年11月03日 星期四 15:12
现在的问题是这样的: 我的这个程序是想在每次运行的时候就检查iWorkFolder下有没有iFolderName这个目录,有就pass,没有就建立。源码如下: import os,string,time iWorkDir=os.path.normpath('D:\Documents and Settings\Arui\桌面\工作夹') iDirList=os.listdir(iWorkDir) iFolderName=string.join(time.ctime().split()[:3],'-') if(iFolderName in iDirList): pass else: iNewFolder=os.path.join(iWorkDir,iFolderName) os.mkdir(iNewFolder) 在cmd下运行: 1,我把它保存为cp936,gb2312编码,报错如下: D:\Documents and Settings\Arui\桌面\工作夹>python work.py sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 2,保存为utf-8编码,报错如下: D:\Documents and Settings\Arui\桌面\工作夹>python work.py sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 现在看来已经不是空格的问题了,而是unicode编码的问题,
2005年11月03日 星期四 15:26
参考下文: http://blog.donews.com/ygao/archive/2005/10/22/598237.aspx On 11/3/05, Du Jun <jdu at haiercct.com.cn> wrote: > > 现在的问题是这样的: > 我的这个程序是想在每次运行的时候就检查iWorkFolder下有没有iFolderName这个目录,有就pass,没有就建立。源码如下: > > import os,string,time > iWorkDir=os.path.normpath('D:\Documents and Settings\Arui\桌面\工作夹') > iDirList=os.listdir(iWorkDir) > iFolderName=string.join(time.ctime().split()[:3],'-') > > if(iFolderName in iDirList): > pass > else: > iNewFolder=os.path.join(iWorkDir,iFolderName) > os.mkdir(iNewFolder) > > > 在cmd下运行: > 1,我把它保存为cp936,gb2312编码,报错如下: > > D:\Documents and Settings\Arui\桌面\工作夹>python work.py > sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on > line 2, > but no encoding declared; see http://www.python.org/peps/pep-0263.html for > details > > 2,保存为utf-8编码,报错如下: > > D:\Documents and Settings\Arui\桌面\工作夹>python work.py > sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on > line 2, > but no encoding declared; see http://www.python.org/peps/pep-0263.html for > details > > 现在看来已经不是空格的问题了,而是unicode编码的问题, > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -- ■■■■■■■■■■■■■■■■■■■■■ Myblog: http://blog.donews.com/ygao/ 自建的python学习论坛: http://groups.google.com/group/python_study ■■■■■■■■■■■■■■■■■■■■■ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051103/a0835d01/attachment.htm
2005年11月03日 星期四 15:26
Du Jun wrote: [...略...] > 在cmd下运行: > 1,我把它保存为cp936,gb2312编码,报错如下: > > D:\Documents and Settings\Arui\桌面\工作夹>python work.py > sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on line 2, > but no encoding declared; see http://www.python.org/peps/pep-0263.html for details > > 2,保存为utf-8编码,报错如下: > > D:\Documents and Settings\Arui\桌面\工作夹>python work.py > sys:1: DeprecationWarning: Non-ASCII character '\xd7' in file work.py on line 2, > but no encoding declared; see http://www.python.org/peps/pep-0263.html for details > > 现在看来已经不是空格的问题了,而是unicode编码的问题, DeprecationWarning仅仅是warning而已,不是错误。 在源文件中使用非ASCII字符集,最好在头两行声明一下编码,如: # encoding: utf-8 参见PEP 0263 -- Defining Python Source Code Encodings http://www.python.org/peps/pep-0263.html -- Qiangning Hong, Registered Linux User #396996 My Blog: http://www.hn.org/hongqn RSS: http://feeds.feedburner.com/hongqn
Zeuux © 2025
京ICP备05028076号