write 中文 into c:\t1

MRAB python at mrabarnett.plus.com
Thu Jan 26 21:53:18 EST 2012


On 27/01/2012 02:46, contro opinion wrote:
> |>>>  s='\xd6\xd0\xce\xc4'
>
>>>>  print  s
>>>>  中文
>
>>>>  s1=s.decode('gbk').encode('utf-8')
>
>>>>  print  s1
>>>>  涓枃
>
>>>>  file=open('c:\\t1','w')
>
>>>>  file.write(s1)
>
>>>>  file.close()
> |
>
> when i open c:\t1,i get 中文 in it,
> how can i write 涓枃 into c:\t1??
>
>  >>> file.write(print s1)
> File "<stdin>", line 1
> file.write(print s1)
> ^
> SyntaxError: invalid syntax
>
file.write(s.decode('gbk').encode('utf-8'))



More information about the Python-list mailing list