A question??

Robert Brewer fumanchu at amor.org
Thu Aug 26 01:56:51 EDT 2004


Ishwar Rattan wrote:
> I thought that Python has no concept of reference/pointer
> (probably incorrect assumption). I saw the following piece of code:
> 
> ...
> def run(program, *args):
>     pid = os.fork()
>     if not pid:
>          os.execvp(program, (program,)+args)
> ...
> 
> and call to run as
> 
> run("pyhton", "a.py")
> 
> What is the interpretation of *args (in def run(..)?
> Looks like a reference to me, so, how does one decide when to use
> a reference or not?

http://docs.python.org/ref/function.html

Basically, *args collects any additional positional arguments passed to
the function. So you can call

run("python", "a.py")

...and...

run("top", "d 5", "s")

...with the same function signature. In the second case, args would
equal the tuple ("d 5", "s") within the run() function.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list