Why has 'dir()' changed in Python 2.2?
Hans Nowak
wurmy at earthlink.net
Fri Feb 1 23:10:52 EST 2002
"Dr. David Mertz" wrote:
>
> I just noticed a change in Python 2.2... that turns out to break my
> [xml_pickle] module. It shouldn't be hard to fix (although I *do* have
> a decision to ponder about the best fix)... but I mostly wonder what the
> thoughts behind the change were (it seems like it will break a lot of
> code that is moderately introspective).
The descrinto document explains why:
http://www.python.org/2.2/descrintro.html#introspection
"In classic Python, the method names of lists were available as
the __methods__ attribute of list objects, with the same effect
as using the built-in dir() function. [...] Under the new proposal,
the __methods__ attribute no longer exists. [...] Instead, you can
get the same information from the dir() function, which gives more
information."
Apparently, it was expected that not much code would break.
Personally, I only use dir() in interactive sessions, to quickly
inspect a module or (other) object. For introspection in
programs, I usually inspect the object's __dict__.
--
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
More information about the Python-list
mailing list