"my brain hurts" or is isinstance broken?
David Mertz, Ph.D.
mertz at gnosis.cx
Thu Jul 4 00:53:09 EDT 2002
|> if isinstance(source, type) or isinstance(source, types.ClassType)
|> return source()
|> else:
|> return copy.copy( source )
|that is exactly what i did. but i dont like this solution cause
|as i told before it is rather implicit than explicit.
FWIW, I faced much the same sort of problem answering these niggly
questions across Python versions, and old- and new-style classes. While
I can't promise I have the final and best solutions to such questions, I
collected a bunch of (mostly binary) functions together in my
gnosis.util.introspect module.
The package encompassing introspect.py can be found from:
http://gnosis.cx/download/Gnosis_XML_Util.ANNOUNCE
Btw. introspect.py works perfectly well in Python 1.5.1 through 2.2
(with just a slight bit of version checking involved).
I welcome any suggestions on what other helper functions might be useful
in answer these introspective questions. I'd love to include more; and
I'd especially love to have a well-known module (like mine :-)) that
collected the best answers in one place.
--
---[ to our friends at TLAs (spread the word) ]--------------------------
Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego
White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad
---[ Postmodern Enterprises <mertz at gnosis.cx> ]--------------------------
More information about the Python-list
mailing list