Testing a module's return

Joal Heagney sctheagn at kraken.itc.gu.edu.au
Thu Apr 20 01:30:11 EDT 2000


I've found that I have to define several of my modules such that they
return a string if they fail, rather than 0. (Let's face it, there are a
lot more things that can go wrong than right). Now I originally wanted
to have these modules return the values I was after. eg.

def function_name(arg1, arg2, arg3, .... argN):
    do something with the args, return value

But as a beginner, *grins* I've found returning error strings a little
more important

def function_name(arg1, arg2, arg3, .... argN):
    check for error condition 1:
        return 'Whoops'
    check for error condition 2:
        return 'What are you doing, Dave?'
    check for error condition 3:
        return 'That ain't right, or humanly decent either'
    do something with the args, return something.

I can't sort out, should I return 0 for a success, and give the answer
as a set attribute (Eg. a class variable)? Or is there a much neater way
of doing things? There'd have to be.

I'd appreciate if answers were posted by email as well as newsgroup. It
could take me a while to get back to them. Thank you,

Joal Heagney/AncientHart




More information about the Python-list mailing list