os.path.join
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed May 2 03:22:48 EDT 2007
En Wed, 02 May 2007 04:03:56 -0300, <half.italian at gmail.com> escribió:
> On May 1, 11:10 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> The right usage is os.path.join(*pathparts)
>
> Wow. What exactly is that * operator doing? Is it only used in
> passing args to functions? Does it just expand the list into
> individual string arguments for exactly this situation? Or does it
> have other uses?
When calling a function, it is used to pass a sequence as positional
arguments. Similarly, **values is used to pass a dictionary as keyword
arguments.
When defining a function, *args receives the remaining positional
arguments not already bound to another parameter; and **kwargs receives
the remaining keyword arguments not already bound to another parameter.
[There is nothing special on the *args and **kwargs names, only the * and
** are important]
See section 4.7 on the Python Tutorial
http://docs.python.org/tut/node6.html#SECTION006700000000000000000 and
specially section 4.7.4 Unpacking Argument Lists.
For a more technical description (but sometimes necesary) read the Python
Reference Manual http://docs.python.org/ref/calls.html
--
Gabriel Genellina
More information about the Python-list
mailing list