Evaluating python - a question

Just van Rossum just at letterror.com
Fri May 18 03:40:44 EDT 2001


Christian Tanzer wrote:

> > Other than that, the suggestion to use accessor methods, instead of
> > accessing the datamembers directly, is probably another good tip.
> 
> Accessor methods won't do anything to prevent typos -- you have an
> equal chance of mistyping the name of the accessor as mangling the
> attribute name.

Equal chance of mistyping, yes, but the point was that a typo in an
accessor method triggers an exception, whereas simply setting an
attribute does not:

class Foo:
    def __init__(self):
        self.foo = 1
    def setFoo(self, value):
        self.foo = value

f = Foo()
f.fooo = 2    # no exception
f.setFooo(2)  # boom

Just



More information about the Python-list mailing list