Tim Johnson wrote:
 What is the difference between using
 hasattr(object, name)
 and
 name in dir(object)
 ?

Did you read the Fine Manual?

http://docs.python.org/library/functions.html#dir

"The default dir() mechanism behaves differently with different types of objects, as it attempts to produce the most relevant, rather than complete, information: ... Note: Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases."


And here's an example:

>>> class C(object):
...     pass
...
>>> hasattr(C, '__eq__')
True
>>> '__eq__' in dir(C)
False



--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to