Need help with Python class idioms

A.Schmolck a.schmolck at gmx.net
Wed Jan 21 15:57:53 EST 2004


tad at tadland.net (Tad Marko) writes:
> Can anyone suggest a more Pythony way to do the following?
> 
> Thanks,
> Tad
> 
> #!/bin/env python
> 
> class A:
>     def __init__(self):
>         self.mandatoryVar1 = None
>         self.mandatoryVar2 = None
> 
>     def setMV1(self, mv1):
>         self.mandatoryVar1 = mv1
> 
>     def setMV2(self, mv2):
>         self.mandatoryVar2 = mv2
> 
>     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."
> 
>         # Using db, do whatever saving stuff is needed.

class A(object):              
      def saveToDB(self, db):
          # Using db, do whatever saving stuff is needed.

'as



More information about the Python-list mailing list