请教python的字符问题。以下代码在eric4和原生IDEL下执行结果不一致:
- #!python
- import sys
- a = sys.getdefaultencoding()
- print 'a is ', a
- b = sys.stdin.encoding
- print 'b is ', b
- c = sys.stdout.encoding
- print 'c is ', c
- str1 = raw_input('say something:')
- print str1
- str2 = raw_input('say something:').split(',')
- print str2
eric4下的执行结果:
a is ascii
b is utf-8
c is utf-8
say something:1,2,3,a,b,c
1,2,3,a,b,c
say something:1,2,3,a,b,c
[u'1', u'2', u'3', u'a', u'b', u'c']
原生IDEL下的执行结果:
a is ascii
b is cp936
c is cp936
say something:1,2,3,a,b,c
1,2,3,a,b,c
say something:1,2,3,a,b,c
['1', '2', '3', 'a', 'b', 'c']
关于b和c,是我配置了eric4的stdin和stdout,这个没有疑问。只是关于split的操作结果,在eric4下为何会自动转unicode,这一点请解惑,谢谢。 |