Need help with Python class idioms

James Henderson james at logicalprogression.net
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
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/





More information about the Python-list mailing list