A question??

Alex Martelli aleaxit at yahoo.com
Thu Aug 26 10:35:14 CEST 2004


Ishwar Rattan <rattan at cps.cmich.edu> wrote:

> I thought that Python has no concept of reference/pointer
> (probably incorrect assumption). 

No pointers, but any name you use, any slot in a list, any key or value
slot in a dict, etc, IS a reference.  Nothing to do with your question
anyway.

> 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(..)?

It is: 'run' takes any number of positional arguments after the ones
specified so far.  Python collects them all into a tuple and your code
refers to that tuple with the name 'args'.

> Looks like a reference to me, so, how does one decide when to use
> a reference or not?

'args' is a reference just like any other name is.

> Any pointers to info will be appreciated.

"Python in a Nutshell", among other reference works, covers argument
passing and such subjects quite well, I think;-).


Alex



More information about the Python-list mailing list