what's the biggest difference between dir and __dict__ in python
class C(object): def f(self): print self.__dict__ print dir(self) c = C() c.f() output: {} ['__class__', '__delattr__','f',....] why there is not a 'f' in self.__dict__ Martijn Pieters dir() does much more than look up __dict__ First of all, dir() is a API method that knows how to use attributes like __dict__ to look up attributes of an object. Not all objects have a __dict__ attribute though. For example, if you were to add a __slots__ attribute to your custom class, instances of that class won't have a __dict__ attribute, yet dir() can still list the available attributes on those instances: