read(size=-1)
Steve Holden
steve at holdenweb.com
Tue Aug 7 02:39:05 EDT 2007
7stud wrote:
> Suppose I write:
>
> f = open("myimg.jpg")
> f.read(10)
>
>
> According to the docs,
> -----------
> read([size])
>
> Read at most size bytes from the file....The bytes are returned as a
> string object.
> ----------
>
> How does python convert a byte to a string?
>
Each byte of the file occupies one character in the string. As you could
have found out (more quickly than posting!) by actually typing your
example into an interpreter.
>>> f = open('desktop01-real.jpg')
>>> f.read(10)
'\xff\xd8\xff\xe0\x00\x10JFIF'
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list