EOF for binary?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sat Jan 8 15:48:26 EST 2005


In <1105147072.909665.242360 at z14g2000cwz.googlegroups.com>, flamesrock
wrote:

> os.path.getsize(infile) <= infile.tell()
> 
> Because that returns the error:
> #  File "/usr/lib/python2.3/posixpath.py", line 142, in getsize
> #    return os.stat(filename).st_size
> #TypeError: coercing to Unicode: need string or buffer, file found
> for me.

This error message gives a good hint what's wrong with your code snippet.

>>> f = open('tmp.txt')
>>> os.path.getsize(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.3/posixpath.py", line 142, in getsize
    return os.stat(filename).st_size
TypeError: coercing to Unicode: need string or buffer, file found

Something expected a string instead of a file object.

>>> os.path.getsize("tmp.txt")
28190L

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list