User Tools

Site Tools


python_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python_examples [2019/03/09 08:06] g00r00python_examples [2019/03/09 21:40] (current) – [Simple File Lister] g00r00
Line 276: Line 276:
  
 writeln("|CR|12Program complete: Press a key|PN"); writeln("|CR|12Program complete: Press a key|PN");
 +</file>
 +
 +===== View Dictionaries and Lists =====
 +<file python dump.mpy>
 +from mystic_bbs import *
 +
 +# Dump contents of a dictionary or list to the screen with
 +# screen pause
 +
 +def dump (obj, linecount):
 +  if linecount == 1:
 +    textcolor(7)
 +  if type(obj) == dict:
 +    for k, v in obj.items():
 +      if hasattr(v, '__iter__'):
 +        writeln(k)
 +        dump(v, linecount)
 +      else:
 +        writeln ("{} : {}".format(k,v))
 +      linecount = linecount + 1
 +      if linecount == 23:
 +        write("|PA|07")
 +  elif type(obj) == list:
 +    for v in obj:
 +      if hasattr(v, '__iter__'):
 +        dump(v, linecount)
 +      else:
 +        writeln ("{}".format(v))
 +        linecount = linecount + 1   
 +        if linecount == 23:
 +          write("|PA|07")
 +  else:
 +    writeln("{}".format(obj))
 +    linecount = linecount + 1
 +    if linecount == 23:
 +      write("|PA|07")
 +
 +# grab the current user and dump the contents of their user dictionary
 +# This function can be used to dump anything, users, bases, groups, etc
 +
 +writeln("|CL|14Dumping contents of user:|07")
 +user = getuser(0)
 +dump(user, 1)
 </file> </file>
python_examples.txt · Last modified: 2019/03/09 21:40 by g00r00

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki