Given a python object of any kind, is there an easy way to get a list of all methods that this object has? Or, if this is not possible, at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called.
+2
A:
You can use the built in dir() function to get a list of all the attributes a module has. Try this at the command line to see how it works.
>>> import moduleName
>>> dir(moduleName)
Also, you can use the hasattr(module_name, "attr_name") function to find out if a module has a specific attribute.
See the Guide to Python introspection for more information.
Bill the Lizard
2008-08-29 15:36:55
+1
A:
On top of the more direct answers, I'd be remiss if I didn't mention iPython. Hit 'tab' to see the available methods, with autocompletion.
And once you've found a method, try help(object.method) to see the pydocs, method signature, etc.
Ahh... REPL.
jmanning2k
2008-08-29 15:47:04