Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Created June 23, 2014 11:55
Show Gist options
  • Save maliubiao/6bc479b503b0ad372f4e to your computer and use it in GitHub Desktop.
Save maliubiao/6bc479b503b0ad372f4e to your computer and use it in GitHub Desktop.
python blt type size
import sys
class kls():
def m(self): pass
def func():
pass
def gen():
yield 1
types = (
type(None), #None
type(1), #int
type(1L), #long
type(1.0), #float
type(True), #bool
type(b'abc'), #bytearray
type(u'a'), #unicode
type("str"), #str
type(complex(1, 1)), #complex
type({1: 2}),
type((1, 2)), #tuple
type([1,2,3]), #list
type(set({1:2})), #set
type(frozenset({1:2})), #frozenset
type(NotImplemented), #NotImplemented
type, #type itself, alias: type(object)
type(func), #function
type(property(1)), #property
type(kls()), #instance
type(kls().m), #method
type(enumerate([])), #enumerate
type(reversed([])), #reversed
type(slice(1, 10, 2)), #slice
type(sys), #module
type(staticmethod(func)), #staticmethod
type(classmethod(func)), #classmethod
type(lambda: None), #lambda
type(func.func_code), #code object
type(sys._current_frames().values()[0]), #frame object
type(gen()), #generator
file, #file
xrange, #xrange
type(len), #blt function
type(tuple().count), #blt method
)
def main():
of = "{:<30}{:<10}{:<10}{:<20}"
print of.format("type", "basicsize", "itemsize", "mro")
for type in types:
print of.format(str(type),
type.__basicsize__,
type.__itemsize__,
type.__mro__)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment