A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-July/081497.html below:

[Python-Dev] fileobj.read(float): warning or error?

[Python-Dev] fileobj.read(float): warning or error? [Python-Dev] fileobj.read(float): warning or error?Leif Walsh leif.walsh at gmail.com
Tue Jul 22 08:35:54 CEST 2008
On Tue, 22 Jul 2008, Cameron Simpson 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?

I think read(0) should be a no-op, just like it is in libc.  This lets
you write 'read(bytes)' without worrying about checking bytes, and
also lets you silently stop reading when you have no more space, like
in the following:

buf = f.read(max(bytes_left, page_size))
while buf:
  process(buf)  # updates bytes_left
  buf = f.read(max(bytes_left, page_size))

-- 
Cheers,
Leif
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4