Call a Python file with parameters

Ulrich Petri ulope at
Mon Jun 9 17:24:48 CEST 2003

"martin z" <pxtl at> schrieb im Newsbeitrag
news:Dr1Fa.38532$j9%.18920 at
> 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
> file you can run with arguments, but the arguments are strings.
> 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
> module (containing functions).

# cat
def somefunc(blah1, blah2):
    return (blah1, blah2)

# cat
import func

print func.somefunc(1,2)



Ciao Ulrich

More information about the Python-list mailing list