Embedding Python and built-in types

Mickael Putters pylist at dreamingprophet.com
Fri Nov 29 16:04:11 EST 2002


Well, I was talking about the assignment operator, maybe it's not =.
Yeah well guess I'll have to modify the source, I thought maybe there would
be a way to do that already present in Python/C.
Anyway, thanks.

----- Original Message -----
From: "Martin v. Löwis" <martin at v.loewis.de>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Friday, November 29, 2002 9:57 PM
Subject: Re: Embedding Python and built-in types


> "Mickael Putters" <mputters at dreamingprophet.com> writes:
>
> > Is it possible to embed it so that you have control over the simple
> > types operators ?
>
> You can overload those operators for user-defined types. For builtin
> types, the builtin implementation is used.
>
> > Basically, that you can for example handle yourself the operator =
> > for integers (actually, just being notified of it happening is
> > enough, since it's to compile some part of the language to
> > bytecode).
>
> I assume you are talking about the equality operator here, which is
> spelled ==.
>
> When embedding Python, please understand that you have the full
> source; Python is free software. So if you want to modify the
> implementation of integer comparison: feel free to. It is in
> Objects/intobject.c:int_compare.
>
> If you don't want to modify the source, you have to understand that
> Python does not implement an equality operator for the int type
> (although it does so for other types). For types not implementing ==,
> Python uses their compare operation instead, which gives -1/0/1; if
> the result is 0, the values are equal.
>
> If you can accept to modify that instead of == operator, then you can
> modify, at run time, PyInt_Type.tp_compare. All uses of the compare
> function should use this function pointer, so your code should be
> called instead of the standard compare implementation.
>
> HTH,
> Martin
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list