From: Ian Jackson Date: Sun, 26 Nov 2017 16:45:50 +0000 (+0000) Subject: moedebug: switch to another new api (nfc) X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=dbcab0f11d4b5ff48608e7fff4dfa479632fc92a;p=moebius3.git moedebug: switch to another new api (nfc) assigning to a module global from outside the module does not work Signed-off-by: Ian Jackson --- diff --git a/gensymbolic b/gensymbolic index 0ab8269..6506777 100755 --- a/gensymbolic +++ b/gensymbolic @@ -6,7 +6,7 @@ from optparse import OptionParser import sympy import symbolic -from moedebug import dbg_file, dbg +from moedebug import * opt_parser = OptionParser() opt_parser.add_option('-q',dest='quiet',action='store_true', @@ -21,8 +21,8 @@ assert(not len(args)) if (not options.ascii) and sys.stdout.encoding is None: sys.stdout = codecs.open("/dev/stdout", "w", 'utf-8') -dbg_file = None if options.quiet else sys.stdout -if dbg_file: +if not options.quiet: dbg_file(sys.stdout) +if dbg_enabled(): sympy.init_printing(use_unicode=(not options.ascii), num_columns=options.width) diff --git a/moedebug.py b/moedebug.py index ac9caeb..d4774f9 100644 --- a/moedebug.py +++ b/moedebug.py @@ -1,7 +1,14 @@ -dbg_file = None -def dbg(*args): - if dbg_file: - print('D ', *args, file=dbg_file) +_files = [] + +def dbg_file(f): + _files.append(f) +def dbg_enabled(): + return not not _files + +def dbg(*args): + for f in _files: + print('// D ', *args, file=f) + f.flush() diff --git a/symbolic.py b/symbolic.py index 0f2ff03..3d17dcb 100644 --- a/symbolic.py +++ b/symbolic.py @@ -2,7 +2,7 @@ from sympy import * import itertools -from moedebug import dbg_file +from moedebug import * from sympy.utilities.lambdify import lambdify, implemented_function @@ -12,11 +12,11 @@ r, theta, s, la, mu, kappa = symbols('r theta s lambda mu kappa') # rightvars replaces def dprint(*args): - if not dbg_file: return + if not dbg_enabled(): return print(*args) def dbg(*args): - if not dbg_file: return + if not dbg_enabled(): return for vn in args: print('\n ' + vn + '\n') pprint(eval(vn))