Re: [問題] 輸出中文text檔案

看板Python作者 (我抓得到什麼呢?)時間11年前 (2012/11/28 00:15), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
: txtContent=open(address) : txt=open('check.txt','w') : c = 0 這是在做什麼@@? : for line in txtContent: : if c == 0: : c+=1 : continue what does c do? : no,addr = line.split(',') : a = [no,addr] : b =str(a) python的str不是這樣用的: >>>help(str) Help on class str in module __builtin__: class str(basestring) | str(object) -> string | | Return a nice string representation of the object. | If the argument is a string, the return value is the same object. 他比較像是repr: 出來的東西可以eval回原本的樣子 然後你給它的東西是一個list!!!!! 所以他給你的答案是list expression,裡面的東西是byte representation : txt.write(b) : print b list expression printed. 同時,python2的print `statment', 對不同的東西有不同的印法... list內的東西就是照byte印出來 for i in b: print i, 才會是你要的東西: print `string'時,把內容直接推進stdout : txtContent.close() : txt.close() : 但輸出結果如下: : ['\x001\x00', : '\x00\xd8\x9a\xc4\x96\x02^\x1fW\xab^2\x00\xef\x8d2\x006\x003\x00_\x86\r\x00\n'] : ['\x002\x00', '\x00\xd8\x9a\xc4\x96\x02^^t][W\x886\x004\x00_\x86\r\x00\n'] : ['\x003\x00', : '\x00\xd8\x9a\xc4\x96\x02^"o\x11l\xef\x8d1\x003\x008\x00_\x86\r\x00\n'] : 請問這要如何解決><? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.245.32
文章代碼(AID): #1GjEScYf (Python)
文章代碼(AID): #1GjEScYf (Python)