[issue17629] Expose string width to Python

Chris Angelico report at bugs.python.org
Thu Apr 4 00:17:53 CEST 2013


Chris Angelico added the comment:

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.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17629>
_______________________________________


More information about the Python-bugs-list mailing list