Inheritance
Brian van den Broek
broek at cc.umanitoba.ca
Tue May 22 15:01:53 EDT 2007
HMS Surprise said unto the world upon 05/22/2007 02:40 PM:
> I am trying to understand the 'if' statement and the exec statement in
> the code below. I would like to add several common routines to this
> class and then inherit it into a class in another file. This other
> class would need to access these common functions as well as inherit
> the PyHttpTestCase class. In particular what is the purpose of the
> surrounding plus signs? May I assume the if statement overrides an
> imported assignment statement.
>
>
> Thanks,
>
> jh
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> from PyHttpTestCase import PyHttpTestCase
> from com.bitmechanic.maxq import Config
> global validatorPkg
> if __name__ == 'main':
> validatorPkg = Config.getValidatorPkgName()
> # Determine the validator for this testcase.
> exec 'from '+validatorPkg+' import Validator'
The if test is, AFAICT, ensuring that validatorPkg is defined.
Config.getValidatorPkgName() likely returns a string. The + signs are
just concatenating a string to be exec'ed:
>>>> validatorPkg = 'some string returned by getValidatorPkgName()'
>>>> 'from '+validatorPkg+' import Validator'
> 'from some string returned by getValidatorPkgName() import Validator'
>>>>
>
HTH,
Brian vdB
More information about the Python-list
mailing list