how to use bool
bukzor
workitharder at gmail.com
Fri Jan 4 11:51:45 EST 2008
On Jan 3, 7:49 am, jimgarde... at gmail.com wrote:
> hi, i have some code where i set a bool type variable and if the value
> is false i would like to return from the method with an error msg..
> being a beginner I wd like some help here
>
> class myclass:
> .........
> def mymethod(self):
> success=True
> msg="all validation OK"
> success=validateSthing()
> if(success==False):
> msg="sthing failed"
> return (success,msg)
>
> dosomeprocessing()
> .....
> success=validateSthingelse()
> if(success==False):
> msg="sthingelse failed"
> return (success,msg)
> domoreprocessing()
> ....
> return(success,msg)
>
> i would like to know if this way of doing this is OK..I have need of
> many kinds of validations in this ..is there a better way of doing
> this ?
>
> thank you
class SthingError(Exception):
def __init__(self, success, msg):
class myclass:
.........
def mymethod(self):
success=True
if not validateSthing():
msg="sthing failed"
return (success,msg)
dosomeprocessing()
.....
if not validateSthingelse():
msg="sthingelse failed"
return (success,msg)
domoreprocessing()
....
return(success,"all validation OK")
More information about the Python-list
mailing list