On Tue, Sep 2, 2008 at 10:05 AM, Jesus Cea <[EMAIL PROTECTED]> wrote:
> Guido van Rossum wrote:
>> On Mon, Jul 21, 2008 at 10:37 PM, Cameron Simpson <[EMAIL PROTECTED]> wrote:
>>> Leaving aside the 0.2 => 0 converstion, shouldn't read() raise an
>>> exception if asked for < 1 bytes? Or is there a legitimate use for read(0)
>>> with which I was not previously aware?
>>
>> Indeed. read(0) is quite often generated as an edge case when one is
>> computing buffer sizes, and returning an empty string is most
>> definitely the right thing to do here (otherwise some application code
>> becomes more complex by having to avoid calling read(0) at all).
>
> How do you differenciate between that empty string (when doing
> "read(0)"), from EOF (that is signaled by an empty string)?.

You don't. If you want to know whether you hit EOF you should try
reading a non-zero number of bytes. (Also note that getting fewer
bytes than you asked for is not enough to conclude that you have hit
EOF.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to