[Tutor] object size in python is in what units?

Jim Mooney cybervigilante at gmail.com
Tue Jul 23 09:09:00 CEST 2013


I've noticed that when I create a number of objects from a class, one after
another, they're at different IDs, but the IDs all appear to be
equidistant, so that they all appear to have the same size. But what does
that size represent? is it bytes? ie - if I run this over and over I get
different id numbers but they are always 40 apart. Or is that distance
machine-specific as to units?:

#Using Python 2.7 on Win 7
from __future__ import division, print_function

class Kronk:
    def __init__(self, zar):
        self.zar = zar
    def getzar(self):
        return self.zar
    def getself(self):
        return id(self)

lardKronk = Kronk('ziggle')
newKronk = Kronk('barf')
budKronk = Kronk('baloney')

print(lardKronk.getzar())
print(newKronk.getzar())
print(budKronk.getzar())

print(lardKronk.getself())
print(newKronk.getself())
print(budKronk.getself())

'''result:
ziggle
barf
baloney
41599624 - different results for each run but always 40 apart
41599664
41599704
'''
-- 
Jim

When I was young dad told me if a moth fluttered onto my sleeping lips at
night
it would suck out my soul.

Dad was such a kidder.

But I still flee from moths.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130723/05d9600a/attachment-0001.html>


More information about the Tutor mailing list