another newbie question: why should you use "*args" ?
s.mientki at id.umcn.nl
Wed Jan 31 15:05:10 CET 2007
> It's bad practice to use built-ins like 'list' as a regular variable
ok, but it was just an example (in practice, I always use very long
>> # calling method 1:
>> execute (S, S )
>> # calling method 2:
>> execute ( ( S, S ) )
> Let's take a look at those side-by-side:
> execute (S, S )
> execute ( ( S, S ) )
> Now, which one *looks* better?
>> # or *the extra flexibility)
>> mylist = ( S, S )
>> execute ( mylist )
> Also, take into consideration the opposite end of the pole; you have
> your list of arguments (args), and your about to call a function that
> was declared something like this:
> def someFunction(arg1, arg2, arg3):
> # etc.
> Which is clearer?
> someFunction(args, args, args)
> And if you've got a variable number of arguments, it becomes virtually
> impossible to avoid using the *args syntax.
# So with this construct, I have all flavours:
if len(args)==1: my_example_var = args
else: my_example_var = args
for i in range ( len ( my_example_var ) ):
... do something with my_example_var [i]
# calling the procedure
chunk_plot (S, S)
chunk_plot ( ( S, S ) )
my_action_list = ( S, S )
chunk_plot ( my_action_list )
And sorry, no need for kwargs for now ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list