python_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python_examples [2019/03/08 08:02] – g00r00 | python_examples [2019/03/09 21:40] (current) – [Simple File Lister] g00r00 | ||
---|---|---|---|
Line 129: | Line 129: | ||
<file python mcihelp.mpy> | <file python mcihelp.mpy> | ||
- | |||
import mystic_bbs as bbs; | import mystic_bbs as bbs; | ||
Line 165: | Line 164: | ||
# List files in the user's current file base | # List files in the user's current file base | ||
- | from time import * | ||
from mystic_bbs import * | from mystic_bbs import * | ||
Line 199: | Line 197: | ||
# Seek to the first file in the list and loop while a file is found calling | # Seek to the first file in the list and loop while a file is found calling | ||
- | # next after each message | + | # next after each file so the next one will be loaded. |
# called before cycling through the list | # called before cycling through the list | ||
Line 217: | Line 215: | ||
writeln("" | writeln("" | ||
writeln(" | writeln(" | ||
- | writeln(" | + | writeln(" |
writeln(" | writeln(" | ||
writeln(" | writeln(" | ||
Line 278: | Line 276: | ||
writeln(" | writeln(" | ||
+ | </ | ||
+ | |||
+ | ===== 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, ' | ||
+ | writeln(k) | ||
+ | dump(v, linecount) | ||
+ | else: | ||
+ | writeln ("{} : {}" | ||
+ | linecount = linecount + 1 | ||
+ | if linecount == 23: | ||
+ | write(" | ||
+ | elif type(obj) == list: | ||
+ | for v in obj: | ||
+ | if hasattr(v, ' | ||
+ | dump(v, linecount) | ||
+ | else: | ||
+ | writeln (" | ||
+ | linecount = linecount + 1 | ||
+ | if linecount == 23: | ||
+ | write(" | ||
+ | else: | ||
+ | writeln(" | ||
+ | linecount = linecount + 1 | ||
+ | if linecount == 23: | ||
+ | write(" | ||
+ | |||
+ | # 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(" | ||
+ | user = getuser(0) | ||
+ | dump(user, 1) | ||
</ | </ |
python_examples.txt · Last modified: 2019/03/09 21:40 by g00r00