How to pass parameter to a module?

Ulrich Petri ulope at gmx.de
Thu Sep 18 08:19:08 EDT 2003


"M-a-S" <NO-MAIL at hotmail.com> schrieb im Newsbeitrag
news:Vwfab.2454$9G2.2174 at twister.southeast.rr.com...
> I'd like to parametrize a module. That is, to set and pass
> some values into the module, while it is being imported.
> I tried this:
>
>   # sub_1.py -- main program
>   extern = "OK"
>   import sub_2
>   print sub_2.noway # prints 'no extern' :-(
>   # EOF
>
>   # sub_2.py -- parametrized module, parameter is the 'extern' var
>   try:
>      noway = extern
>   except:
>      noway = 'no extern'
>   # EOF
>

It looks like you are using modules where you would rather use functions.
exp:
-------------------cut---------
def sub2(blah=None):
    if blah is None:
       return "no extern"
    else:
        return blah

sub2('test')
sub2()

HTH

Ciao Ulrich






More information about the Python-list mailing list