S. D. Rose <[EMAIL PROTECTED]> wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> S. D. Rose wrote: >> > Hello all. >> > If I read a binary file: >> > >> > file = open('c:\\logo.gif', 'rw'') # Read from FS as one way to get the >> > object, d/l from website another... >> > file.read() >> > >> > is there anyway I can determine the 'size' of the object file? (Without >> > going to the filesystem and reading the filesize from the directory ...) >> >> Once you have read the data you can get the size of that: >> d = file.read() >> print len(d) >> >> Is that what you mean? Otherwise I don't know how you can get the size of >> a file without >> asking the filesystem... > > Yes, len() will do what I want. I didn't realize it would work with binary,
The read() function returns a string (object of type str), whether the file was opened in binary or text mode. Such objects are really a series of bytes which may or may not represent text in some encoding. (By contrast, objects of type unicode definitely do represent text in some Unicode encoding.) > I thought it was good only for variables, lists, etc. Variables? Do you mean tuples? len() works with any kind of sequence, and strings behave as a sequence of 1-byte strings. -- Ben Hutchings It is easier to write an incorrect program than to understand a correct one. -- http://mail.python.org/mailman/listinfo/python-list