mem.py

Created by cent20

Created on February 25, 2020

793 Bytes

Script récupéré ici : https://workshop.numworks.com/python/andreanx/mem


def sizeenv():
  s=0
  import __main__
  for o in dir(__main__):
    try:s+=size(eval(o))
    except:pass
  return s
def size(o):
  s,t=0,type(o)
  if t==str:s=49+len(o)
  if str(t)=="<class 'function'>":s=136
  if t==int:
    s=24
    while o:
      s+=4
      o>>=30
  if t==list:
    s+=64
    for so in o:s+=8+size(so)
  return s
def mem(v=1,r=1):
  try:
    l=[]
    try:
      l+=[r and 793+sizeenv()]
      if v*r:print(" ",l[0])
      l+=[0]
      l+=[""]
      l[2]+="x"
      while 1:
        try:l[2]+=l[2][l[1]:]
        except:
          if l[1]<len(l[2])-1:l[1]=len(l[2])-1
          else:raise(Exception)
    except:
      if v:print("+",size(l))
      try:l[0]+=size(l)
      except:pass
      try:l[0]+=mem(v,0)
      except:pass
      return l[0]
  except:return 0

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.