This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Rosuav
Recipients Rosuav, ezio.melotti, loewis, vstinner
Date 2013-04-03.22:17:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1365027473.38.0.0730940576338.issue17629@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-04-03 22:17:53Rosuavsetrecipients: + Rosuav, loewis, vstinner, ezio.melotti
2013-04-03 22:17:53Rosuavsetmessageid: <1365027473.38.0.0730940576338.issue17629@psf.upfronthosting.co.za>
2013-04-03 22:17:53Rosuavlinkissue17629 messages
2013-04-03 22:17:53Rosuavcreate