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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to