On Tue, 17 Oct 2006 15:50:47 +0200, Alexander Eisenhuth wrote:

> Hello,
> 
> is there a assignement operator, that i can overwrite?

No.

We were just discussing the reasons why Python will not and can not have
an assignment operator just a few days ago. Check the archives for more
details.


> class MyInt:
>       def __init__(self, val):
>               assert(isinstance(val, int))

isinstance() considered harmful:

http://www.canonical.org/~kragen/isinstance/

>               self._val = val

Seems kind of pointless. What does MyInt do that ordinary ints don't?
Apart from slow your program down and require extra programming effort.

> a = MyInt(10)
> 
> # Here i need to overwrite the assignement operator a = 12

Can't happen. "a" is just a name, not an object with methods that can be
called. "a" can be bound to anything, not just MyInt instances. Objects
like MyInt(10) can have no name, one name or many names:

mylist = [0, MyInt(10), 20, 30]  # MyInt instance has no name
x = MyInt(10)  # MyInt instance has one name
x = y = z = MyInt(10)  # MyInt instance has many names



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to