Why has 'dir()' changed in Python 2.2?
Dr. David Mertz
mertz at gnosis.cx
Sat Feb 2 00:58:34 EST 2002
Me, previously:
|> 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)
"Tim Peters" <tim.one at home.com> wrote previously:
|I don't know what you were using it for exactly, but chances
|are good you should be looking at object.__dict__.keys() instead (which
|is all dir() often did before 2.2).
The timbot, as always, can peer through the surface words on the Usenet
into my deepest, dark thoughts. The obj.__dict__.keys() is probably
what I'll change it to, which should restore the old behavior. As the
name suggests, the [xml_pickle] module serializes Python objects to an
XML format... so dir() was a convenient shortcut for asking "what's this
object got?"
I probably should have known better, and -do- vaguely recall some
discussion about dir() on c.l.py around the time 2.2 alphas were coming
out. The thing I want to think about is whether I actually *want* any
of the extra information that dir() gives me; for example, maybe the
docstring.
Do I understand the new behavior correctly in thinking that the
following function is equivalent to dir(), at least for old-style class
instances:
def dir2(o):
lst = o.__dict__.keys()
lst.extend(o.__class__.__dict__.keys())
return lst
Or is there something else thrown in there that this overlooks?
Yours, David...
--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
.cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------
More information about the Python-list
mailing list