1

I kind of wrote this piece of code:

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);

However I'm still receiving this error:

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

I guess it's cos' fileobj contains a list of path...

Does anyone have any suggestions?

1 Answer 1

5

You want

for x in row: # NOT   in fileobj
    filesize = os.path.getsize(x)

By the way, the line x = 0 has no effect but to confuse the unsuspecting reader. You should remove it.

2
  • Thanks a lot!!! amazing!!! and sorry about the mistake but I started programming in python yesterday, I used to program in other programming languages that require that kind of thing... Anyway thanks again
    – nassio
    Feb 6, 2012 at 1:07
  • I'm glad I could help. It sounds like this answer solved your problem. If that's the case, please consider accepting it.
    – phihag
    Feb 6, 2012 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.