And so says Hugh Perkins on 13/03/06 18:59...
> I guess the thing that I find tricky in Python is that it is possible to
> accidentally add unintended properties to a class by misspelling the
> intended one, and sometimes it's tricky to catch this.

It is certainly possible, but it doesn't happen as often as you'd think.

Also - = bar assigns to the instance, not the class.

> For example (my
> Python syntax might be a little rusty..):
> class MyClass():
>    def __constructor__(self, name):
> <> = name
>    def PrintName(self):
>       print "My name is " + self.myname
> myobject = new MyClass("Tom")
> myobject.PrintName()
> gives:
> C:\> python
> My name is

No, it gives an AttributeError exception.  You only "create" new
attributes with an assignment.

And you can constrain even that using slots.  If you're interested,
contact me in private :-) otherwise, just record the fact that it's
possible.  (A class with slots makes all attribute assignments fail
unless the attribute name is in the slots list.)

                                               Lalo Martins
      So many of our dreams at first seem impossible,
       then they seem improbable, and then, when we
       summon the will, they soon become inevitable.
GNU: never give up freedom       

vos-d mailing list

Reply via email to