Re: Commutative object in emulating numbers

2009-09-13 Thread iu2
On Sep 14, 7:52 am, iu2 isra...@elbit.co.il wrote: Hi, I reached the chapter Emulating numeric types in the python documentation and I tried this: class A:         def __mul__(self, a):                 return 'A' * a Now, this works as expected: a = A() a * 3 'AAA' But this

Re: Commutative object in emulating numbers

2009-09-13 Thread Chris Rebert
On Sun, Sep 13, 2009 at 9:52 PM, iu2 isra...@elbit.co.il wrote: Hi, I reached the chapter Emulating numeric types in the python documentation and I tried this: class A:        def __mul__(self, a):                return 'A' * a Now, this works as expected: a = A() a * 3 'AAA' But

Re: Commutative object in emulating numbers

2009-09-13 Thread iu2
On Sep 14, 8:16 am, Chris Rebert c...@rebertia.com wrote: On Sun, Sep 13, 2009 at 9:52 PM, iu2 isra...@elbit.co.il wrote: Hi, I reached the chapter Emulating numeric types in the python documentation and I tried this: class A:        def __mul__(self, a):                return 'A' *

Re: Commutative object in emulating numbers

2009-09-13 Thread Steven D'Aprano
On Sun, 13 Sep 2009 21:52:26 -0700, iu2 wrote: Hi, I reached the chapter Emulating numeric types in the python documentation and I tried this: [...] What do I need to do in order to make the two classes, int and A, commutative? Try adding a __rmul__ method: class A: def