Given a class such as
class MyClass:
text = "hello"
number = 123
Is there a way in python to inspect MyClass an determine that it has the two attributes text and number. I can not use something like inspect.getSource(object) because the class I am to get it’s attributes for are generate using SWIG (so they are hidden in .so 🙂 ).
So I am really looking for something equivalant to Java’s [Class.getDeclardFields][1]
Any help would be appreciated, otherwise I’ll have to solve this problem with SWIG + JAVA instead of SWIG + Python.
I usually just use
dir(MyClass). Works on instantiated objects too.edit:
I should mention this is a shorthand function I use for figuring out if my objects are getting created correctly. You might want to look more carefully into the reflection API’s if you’re doing this programmatically.
Also it may not work on linked libraries.