Use list name as string

Tim Chase python.list at tim.thechases.com
Thu Feb 5 03:31:49 CET 2009


> My argument comes down to; we use M so we don't have to type
> [1,3,5,7], I realize that this is in part because we might not no what
> M will be.
> This is starting to sound like double talk on my part, I have only
> been programing in python for 2 weeks so my credibility is only that
> of an outside that MAY have a reasonable way of thinking of this or at
> least a feature I would like.

The problem (as pointed out elsewhere on the list), an argument 
to a function may have zero or more names at the time the 
function is called.  There *is* *no* canonical name for an 
object. If you want to name an object, pass it as a 
function-argument.  Or use its ID.  However, since Python has the 
flexibility to handle any of the following:

   a = [1,2,3]
   b = [5,6,7]
   c = b

   foo([8,9,10])
   foo(a)
   foo(b)
   foo(c)

While for the b/c name conflict (both refer to the same object), 
might be hackable by sniffing the call-stack, the anonymous 
[8,9,10] argument has *no* name, and thus your function is stuck.

> by the way what is "**kwargs" I can't find any documentation on this?

There's a quick example here:

http://mail.python.org/pipermail/python-list/2007-June/443934.html

-tkc






More information about the Python-list mailing list