Dr. Phillip M. Feldman schrieb:
Some aspects of the Python design are remarkably clever, while others leave
me perplexed. Here's an example of the latter: Why does len() give an error
when applied to an int or float? len() should always return something; in
particular, when applied to a scalar, it should return a value of 1. Of
course, I can define my own function like this:

def mylen(x):
   if isinstance(x,int) or isinstance(x,float): return 1
   return len(x)

But, this shouldn't be necessary.

Can you show some example of where that is actually making a piece of code more elegant?

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to