I want to get the class argument keyword arguments names. I think I understood how to get the names of the methods and how to get the names of the variables for a particular method, but I don’t understand how to combine them:
class A(object):
def A1(self, test1=None):
self.test1 = test1
def A2(self, test2=None):
self.test2 = test2
def A3(self):
pass
def A4(self, test4=None, test5=None):
self.test4 = test4
self.test5 = test5
a = A()
for methodname in a.__class__.__dict__.keys():
print methodname
for varname in a.A1.__func__.__code__.co_varnames:
print varname
for function in class:
print function.name
for varname in function:
print varname
A1
self
test1
A2
self
test2
A3
self
A4
self
test4
test5
I will need to expose the method names and their arguments to the external API. I wrote a twisted application to link to the mentioned api, and this twisted application will have to publish this data via api.
So, I think I will use something like:
for methodname in A.__dict__.keys():
if not methodname.startswith('__'):
print methodname
for varname in A.__dict__[methodname].__code__.co_varnames:
print varname
As the environment becomes more stable, I will think about a better solution.
source
share