Call a Python file with parameters

Ulrich Petri ulope at gmx.de
Mon Jun 9 11:24:48 EDT 2003


"martin z" <pxtl at hotmail.com> schrieb im Newsbeitrag
news:Dr1Fa.38532$j9%.18920 at news04.bloor.is.net.cable.rogers.com...
> I've asked this before, but last time I was too vague.  So, I've got a
> simpler request: I want to write and call Python files as if they were
> functions.  The problem is simple: if you write a Python file with only a
> def-statement, you don't get a file you can run with arguments - you get a
> file that builds a function.  If you use the argc and argv syntax, you get
a
> file you can run with arguments, but the arguments are strings.
Basically,
> I want to have a Python file that, when I compile it, I get nothing but a
> function, or something I can use like a function, that I can shove a
> parameter tuple into.  Instead I get a code object (no argument tuple) or
a
> module (containing functions).
>

-------
# cat func.py
def somefunc(blah1, blah2):
    return (blah1, blah2)

# cat prog.py
import func

print func.somefunc(1,2)

-------------------

HTH

Ciao Ulrich






More information about the Python-list mailing list