get function arguments

B

Benny Mohr

I have a simple function

def myFunc(a,b,c='default'):
...

How can I get the list of argumens of this function?

Benny
 
S

Steven Bethard

Benny Mohr said:
How can I get the list of argumens of this function?

Is this what you mean?
.... pass
.... ('a', 'b', 'c')

I don't know where (if?) the func_code attributes are documented, but you should
be able to figure them out with a little object introspection (e.g. dir or an
editor like PythonWin that does some code completion).

Steve
 
B

Benny Mohr

Thanks a lot, that's what I'm looking for

Benny

Steven said:
Is this what you mean?



... pass
...


('a', 'b', 'c')

I don't know where (if?) the func_code attributes are documented, but you should
be able to figure them out with a little object introspection (e.g. dir or an
editor like PythonWin that does some code completion).

Steve
 
J

Jorge Godoy

Steven Bethard said:
Is this what you mean?

... pass
...
('a', 'b', 'c')

I don't know where (if?) the func_code attributes are documented, but you should
be able to figure them out with a little object introspection (e.g. dir or an
editor like PythonWin that does some code completion).

You could have asked in the interactive prompt as well :)

['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', 'co_argcount', 'co_cellvars',
'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags',
'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals',
'co_stacksize', 'co_varnames']
There seems to be other interesting things here too:
['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__module__',
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults',
'func_dict', 'func_doc', 'func_globals', 'func_name']
 
S

Steven Bethard

Jorge Godoy said:
You could have asked in the interactive prompt as well

Sorry, I guess I wasn't clear. That's what I meant when I said "you should be
able to figure them out with a little object introspection (e.g. dir..." The
interactive prompt (and the dir or help function) is almost always the right
answer to find out about object attributes in Python. =)

Steve
 
J

Jorge Godoy

Steven Bethard said:
Sorry, I guess I wasn't clear. That's what I meant when I said "you should be
able to figure them out with a little object introspection (e.g. dir..." The
interactive prompt (and the dir or help function) is almost always the right
answer to find out about object attributes in Python. =)

I'm the one to say I'm sorry. Before I sent the message I read your
post like I answered, but when I read my answer it sounded completely
different to me :)
 
T

Terry Hancock

Is this what you mean?

... pass
...
('a', 'b', 'c')

I don't know where (if?) the func_code attributes are documented

They're not easy to find, I'll grant you. But this table is pretty
interesting:

http://python.org/doc/2.3.4/lib/inspect-types.html

OTOH, this probably *shouldn't* be too easy to find, as it's not
something you should use until you really *really* need it.

Cheers,
Terry

ziur(--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,211
Messages
2,571,092
Members
47,694
Latest member
digiadvancemarketing

Latest Threads

Top