Hello all,

I'm curious--How do I access a function defaults by name?

for example

def bob(wife, wives=[]):
  # add wife to wives if applicable
  if (can_add_wife(wife,wives)):
    wives.append(wife)
  return len(wives)


Say the bob function is adding to wives. What if you want to see what the wives default is that's being held by the function?

I see you can get at wives with bob.func_defaults, but only if you know in advance which position it is in in the func_defaults tuple. What if I want to get at wives by name? bob.wives seems logical but of course doesn't work. bob.func_code.co_varnames looks like it may work, but won't because it can't tell you where in func_defaults you you want. Other than that, I can't seem to find anything.

By the way, I already know a million "better" ways to do this, so no need for the "why would you want to do that?" responses. I am just curious about python functions here.

Thanks in advance for any insight.

James
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to