Looking for assignement operator

Bruno Desthuilliers onurb at xiludom.gro
Wed Oct 25 05:12:49 EDT 2006


Tommi wrote:
> Bruno Desthuilliers wrote:
> 
(about Traits)
>
>> How could it help ?
> 
> To me they just looked a bit alike:
> 
> --- op's example ---
> a = MyInt(10)
> # Here i need to overwrite the assignement operator
> a = 12
> 
> --- traits' example ---
> moe = Child()
> # NOTIFICATION in action
> moe.age = 10
> 

You do understand the difference between rebinding a name and modifying
a mutable object, do you ?

FWIW, you definitively don't need Traits here - properties are enough.

class Something(object):
  @apply
  def age():
    def fget(self):
      return self._age
    def fset(self, val):
      self._age = MyInt(val)
    return property(**locals())

s = Something()
s.age = 42
type(s.age)

But this is not what the OP was asking for...

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list