![](https://secure.gravatar.com/avatar/0b220fa4c0b59e883f360979ee745d63.jpg?s=120&d=mm&r=g)
Feb. 21, 2006
9:38 p.m.
On Tue, 21 Feb 2006, Guido van Rossum wrote: [...]
If you're only interested in classifying the three specific built-ins you mention, I'd check for the presense of certain attributes: hasattr(x, "lower") -> x is a string of some kind; hasattr(x, "sort") -> x is a list; hasattr(x, "update") -> x is a dict. Also, hasattr(x, "union") -> x is a set; hasattr(x, "readline") -> x is a file.
dict and set instances both have an .update() method. I guess "keys" or "items" is a better choice for testing dict-ness, if using "LBYL" at all. (anybody new to "LBYL" can google for that and EAFP -- latter does not stand for European Assoc. of Fish Pathologists in this context, though ;-)
That's duck typing!
hasattr(python, "quack") True
John