小编tea*_*ish的帖子

AttributeError:“ int”对象没有属性“ write”

我正在读取一个csv文件,并将结果写入日志文件“ p.log”。尽管我在将数据写入文件之前将数据转换为字符串,并通过多次迭代成功完成了此操作,但我一直遇到最终出现此错误的情况:AttributeError:'int'对象没有属性'write'。

我将提供代码片段以及打印到屏幕上的结果:

p=open("p.log","w")

for line in f:#parse lines following the headerline
    line = line.split(",")
    print line, type(str(line))
    p.write('string: '+str(line)+'\n')

['14-04-21 08:30:00.973000', 'EEM06211440.5P', 'EEM', '2014-06-21', '40.50', 'P', '16084', 'AUTO', 'PHLX', '0.82', '10', '0.82', '31', '0.88', '31', '0.06', '0.00', '0.06', 'Y', 'AN', '2', 'AN', '2', 'Bid', '31', '0.0000', '2', 'AN\r\n'] <type 'str'>
['14-04-21 08:30:00.974000', 'MU06211425C', 'MU', '2014-06-21', '25.00', 'C', '0', 'AUTO', 'PSE', '1.57', '11', '1.56', '11', '1.67', '30', '0.11', '0.01', '0.10', 'Y', 'Z', '1', 'IXH', '3', 'Mid', '0', '0', '0', '\r\n'] …
Run Code Online (Sandbox Code Playgroud)

file-io python-2.7

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

file-io ×1

python-2.7 ×1