作者kdjf (我抓得到什麽呢?)
看板Python
标题Re: [问题] 输出中文text档案
时间Wed Nov 28 00:15:30 2012
: 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