Spelling mistakes!

skip at pobox.com skip at pobox.com
Fri Jan 6 14:26:41 EST 2006


    >> try this:
    >> class x(object):
    >>    def __init__(self):
    >>       self.someName = "hello"
    >>    def someMethod(self):
    >>       self.sumName = "bye"

    >> find that bug.

Aside from the other responses (unittests, pychecker/pylint), you might also
consider using __slots__ for new-style classes:

    class x(object):
       __slots__ = ('someName',)
       def __init__(self):
          self.someName = "hello"
       def someMethod(self):
          self.sumName = "bye"

    my_x = x()
    my_x.someMethod()

When run you will get this output:

    Traceback (most recent call last):
      File "slot.py", line 9, in <module>
        my_x.someMethod()
      File "slot.py", line 6, in someMethod
        self.sumName = "bye"
    AttributeError: 'x' object has no attribute 'sumName'

Skip



More information about the Python-list mailing list