我写了这段代码:
import csv
import os
fileobj = csv.reader(open('c:\\paths1.csv', 'rb'), delimiter=' ', quotechar='|')
for row in fileobj:
x=0
for x in fileobj:
filesize= os.path.getsize(x)
print (filesize);
Run Code Online (Sandbox Code Playgroud)
但是我仍然收到这个错误:
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\workspace\test1py\Acol.py", line 9, in <module>
filesize= os.path.getsize(x)
File "C:\Python27\lib\genericpath.py", line 49, in getsize
return os.stat(filename).st_size
TypeError: coercing to Unicode: need string or buffer, list found
Run Code Online (Sandbox Code Playgroud)
我想这是cos'fileobj包含一个路径列表......
有没有人有什么建议?
你要
for x in row: # NOT in fileobj
filesize = os.path.getsize(x)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,这条线x = 0没有效果,只会让毫无戒心的读者感到困惑.你应该删除它.
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |