[問題] Python新手 中文編碼問題
各位前輩好 我的環境是Mac 使用Textwrangler Python是2.6.1
問題是這樣的
#-*- coding: utf-8 -*-
file = open('test.txt', 'w')
str = 'hi how are you '
str = str.decode('utf-8')
str = str.encode('utf-8')
file.write(str)
file.closed
在這個情況下 輸出的text.txt 可以正常顯示
但是只要str = 'hi how are you 嗨你好'
有中文字出現在其中 輸出的檔案Mac系統就會說有未知格式不能開啟
摸索了好久 也爬文跟Google
但好像都沒找到我可以學習的方法
把decode encode那個拿掉也沒啥改變
摸了一整天摸不出頭緒 可以請各位前輩指點一下新手嗎
先說謝謝了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.171.225.165
→
02/14 22:25, , 1F
02/14 22:25, 1F
→
02/14 22:44, , 2F
02/14 22:44, 2F
→
02/14 22:44, , 3F
02/14 22:44, 3F
→
02/14 22:45, , 4F
02/14 22:45, 4F