python2编码。。感觉很奇怪的问题。。

来源:互联网 发布:mac jenkins 开机启动 编辑:程序博客网 时间:2024/05/27 20:54
def format_AbsolutePathFile(file_name):    temp_file=tempfile.TemporaryFile()    with codecs.open(file_name,'r',encoding='utf-8') as source_file:        source_content=source_file.read()        print "source_encoding:",type(source_content)        temp_file.write(source_file.read().encode('utf-8'))    temp_file.seek(0)    read_content= temp_file.read()    print type(read_content)    print type(read_content.decode('utf-8'))


然后,输出结果居然是这个样子。。真是奇怪啊。

source_encoding: <type 'unicode'>
<type 'str'>
<type 'unicode'>


第一个reading返回是unicode,

第二个temp_file.read()居然返回是str。。。

好奇怪。。记录一下。

0 0