Need help with Python class idioms

James Henderson james at
Wed Jan 21 22:01:33 CET 2004

[Tad Marko]
> >     def saveToDB(self, db):
> >         if self.mandatoryVar1 == None:
> >             raise Exception, "Mandatory Var 1 not set."
> >         if self.mandatoryVar2 == None:
> >             raise Exception, "Mandatory Var 2 not set."

P.S. Since you're asking about idiom, it would be more Pythonic to write:

    if self.mandatoryVar1 is None:

using the identity test "is" rather than equality test "==", since there is 
only one None.

James Henderson, Logical Progression Ltd.

More information about the Python-list mailing list