The following should warn you of access to the attribute that caused the AttributeError exception:
>>> fb Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Foo instance has no attribute 'b'
Alternatively, convert Exception to str :
>>> try: ... fb ... except AttributeError, e: ... print e ... Foo instance has no attribute 'b'
If you want to get a list of attributes available for an object, try dir() or help()
>>> dir(f) ['__doc__', '__init__', '__module__', 'a'] >>> help(str) Help on class str in module __builtin__: class str(basestring) | str(object) -> string | | Return a nice string representation of the object. | If the argument is a string, the return value is the same object. | | Method resolution order: | str | basestring | object | | Methods defined here: | | __add__(...) | x.__add__(y) <==> x+y | [...] | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __new__ = <built-in method __new__ of type object> | T.__new__(S, ...) -> a new object with type S, a subtype of T
You can even call help() on dir (why, as an exercise for the reader):
>>> help(dir) Help on built-in function dir in module __builtin__: dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class attributes, and recursively the attributes of its class base classes.
Otherwise, you can always see the code, unless you have been provided with any pre-compiled module by a third-party manufacturer, in which case you should require better documentation from your supplier (for example, some unit tests!)!
Johnsyweb
source share