Message185972
CPython also knows the length of a string, which means that len(s) is a fast operation. I wouldn't expect anyone to rewrite len() as:
def get_string_length(s):
length=0
for ch in s:
length+=1
return length
even though that works. No, we have a built-in function that's able to simply query the header. (Via a special method, but it's still ultimately the same thing.)
The only other use-case that I have at the moment relates to a query on python-list about a broken MySQL, which was unable to handle astral characters. With a simple and fast way to query the string's width, this could have been checked for at practically zero cost; as it is, he had to scan all his strings to find out what was in them. It's not something that's of immense value, but it's a handy introspection, and one that should cost little or nothing to provide. |
|
Date |
User |
Action |
Args |
2013-04-03 22:17:53 | Rosuav | set | recipients:
+ Rosuav, loewis, vstinner, ezio.melotti |
2013-04-03 22:17:53 | Rosuav | set | messageid: <1365027473.38.0.0730940576338.issue17629@psf.upfronthosting.co.za> |
2013-04-03 22:17:53 | Rosuav | link | issue17629 messages |
2013-04-03 22:17:53 | Rosuav | create | |
|