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/2000-October/009971.html below:

[Python-Dev] Wierd buffer "add" behaviour.

[Python-Dev] Wierd buffer "add" behaviour.Greg Stein gstein@lyra.org
Mon, 16 Oct 2000 06:01:26 -0700
On Mon, Oct 16, 2000 at 09:50:22AM +0200, M.-A. Lemburg wrote:
> Mark Hammond wrote:
>...
> > This yields the following strange behaviour:
> > 
> > >>> a=buffer('a')
> > >>> a+a
> > 'aa'
> > >>> a+a+a
> > Traceback (innermost last):
> >   File "<interactive input>", line 1, in ?
> > TypeError: cannot add type "buffer" to string
> > >>>
> > 
> > That doesnt seem correct to me?
> 
> Neither to me.

It is caused by the non-commutative aspect of Python types. You end up with
a string, and that type doesn't know how to add a buffer to itself.

Ideally, it might be nice to allow a string to append any object that
exports the buffer-interface. But when somebody goes and writes
"abc"+my_array ... hoo boy, will we hear complaints.

The alternative is to allow the buffer to resolve the type conflict and do
the appending within the buffer code.

Of course, the choice of returning a string (from buf+buf) rather than a
buffer was arguably the wrong choice.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/



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