On Wed, Apr 3, 2013 at 6:53 PM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > Here's another way: > > > (sys.getsizeof(s) - sys.getsizeof(''))/len(s) > > should work.
Hmm, I had been under the impression that there was a certain "base length" below which strings all had the same size. Yes, that also works; though again, it's something that can be directly queried, at the C level. > There's probably also a way to do it using ctypes. > >> The system already knows what the size is, I was hoping for an >> uber-quick inspection of the string header. > > I'm not sure that I would want strings to have a method reporting this, > but it might be nice to have a function in the inspect module to do so. Yeah, that's why I also looked in 'sys'; 'inspect' might well be a good place for it, too. But it seems such a function doesn't exist, which is what I was asking. ChrisA -- http://mail.python.org/mailman/listinfo/python-list