[Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Ed Singleton
If I have a dictionary:

mydict{'var1':a, 'var2':b}

and I want to pass it to a function as:

myfunc(var1=a, var2=b)

How would I do it?

Thanks

Ed
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Kent Johnson
Ed Singleton wrote:
 If I have a dictionary:
 
 mydict{'var1':a, 'var2':b}

Presumably you mean
   mydict = {'var1':a, 'var2':b}
 
 and I want to pass it to a function as:
 
 myfunc(var1=a, var2=b)
 
 How would I do it?

myfunc(**mydict)

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Ed Singleton
Thanks again.

This does bring up an issue I occaiosionally have with the documentation.

Presumambly myfunc(**mydict) is a fairly trivial thing, but it is very
hard to find when you don't know what you're looking for.  Not sure
what the solution is, but the inability to search for things when you
don't know what they're called is a bit of a stumbling block
sometimes.

Maybe a page that very briefly summarises the 'unsearchable' with
links to fuller descriptions?

Ed

On 15/03/06, Kent Johnson [EMAIL PROTECTED] wrote:
 Ed Singleton wrote:
  If I have a dictionary:
 
  mydict{'var1':a, 'var2':b}

 Presumably you mean
mydict = {'var1':a, 'var2':b}
 
  and I want to pass it to a function as:
 
  myfunc(var1=a, var2=b)
 
  How would I do it?

 myfunc(**mydict)

 Kent

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Kent Johnson
Ed Singleton wrote:
 Thanks again.
 
 This does bring up an issue I occaiosionally have with the documentation.
 
 Presumambly myfunc(**mydict) is a fairly trivial thing, but it is very
 hard to find when you don't know what you're looking for.  Not sure
 what the solution is, but the inability to search for things when you
 don't know what they're called is a bit of a stumbling block
 sometimes.

Yes. This syntax is actually hard to find in the docs when you *do* know 
what you are looking for. The best coverage I could find is in the 
Language Reference which isn't exactly light reading:
http://docs.python.org/ref/calls.html

It's also mentioned in the docs for apply(), which is an older way to do 
the same thing:
http://www.python.org/doc/2.4.2/lib/non-essential-built-in-funcs.html
 
 Maybe a page that very briefly summarises the 'unsearchable' with
 links to fuller descriptions?

Hmm. Sounds a little tricky to put together...

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor