String representation of an identifier's name

Mark McEahern marklists at mceahern.com
Sun Jan 12 16:42:23 EST 2003


> I think it easier to explain with an example, so here it goes:
> Assuming there's a function fn that does what I want, it would 
> work like this:
> 
> g = 23
> foo = {'a':56}
> 
> fn(g) => 'g'
> fn(foo) => 'foo'
> 
> How can I write fn? O:-)

What do you expect fn to do here:

g = 23
h = g
fn(h)

Consider this:

#!/usr/bin/env python

def fn(**args):
    for k, v in args.items():
        print '%s == %s' % (k, v)

fn(g=23)


// m
-






More information about the Python-list mailing list