tipcode1.py

Created by vef03715

Created on January 14, 2022

1.75 KB


def getplatform():
  id=-1
  try:
    import sys
    try:
      if sys.platform=='nspire':id=0
      if sys.platform.startswith('TI-Python') or sys.platform=='Atmel SAMD21':id=4
    except:id=3
  except:
    try:
      import kandinsky
      id=1
    except:
      try:
        if chr(256)==chr(0):id=5+(not ("HP" in version()))
      except:
        id=2
  return id

platform=getplatform()
#lines shown on screen
#plines=[29,12,  7, 9,11,0,0]
plines=[29,16,  7, 9,11,0,0]
#max chars per line
#(error or CR if exceeded)
pcols =[53,99,509,32,32,0,0]

nlines=plines[platform]
ncols=pcols[platform]
curline=0

def mprint(*ls):
  global curline
  st=""
  for s in ls:
    if not(isinstance(s,str)):
      s=str(s)
    st=st+s
  stlines=1+int(len(st)/ncols)
  if curline+stlines>=nlines:
    input("Input to continue:")
    curline=0
  print(st)
  curline+=stlines

def sstr(obj):
  try:
    s=obj.__name__
  except:
    s=str(obj)
    a=s.find("'")
    b=s.rfind("'")
    if a>=0 and b!=a:
      s=s[a+1:b]
  return s

def isExplorable(obj):
  s=str(obj)
  return s.startswith("<") and s.find(" ")>=0 and not s.startswith("<module")

def explmod(pitm,pitmsl=[],reset=True):
  global curline
  if(reset):
    curline=0
    pitmsl=[sstr(pitm)]
  hd="."*(len(pitmsl)-1)
  spath=".".join(pitmsl)
  c,c2=0,0
  spitm=str(pitm)
  for itms in sorted(dir(pitm)):
    c,c2=c+1,c2+1
    try:
      itm=eval(spath+"."+itms)
      mprint(hd+itms+"="+str(itm))
      if isExplorable(itm) and itm!=pitm:
        pitmsl2=pitmsl.copy()
        pitmsl2.append(itms)
        c2=c2+explmod(itm,pitmsl2,False)[1]
    except:
      mprint(hd+itms)
  if c>0 and reset:
    mprint(hd+"Total: "+str(c)+" 1st level item(s)")
    if c2>0 and c2!=c:
      mprint(hd+"       "+str(c2)+" item(s)")
  return [c,c2]

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.