Please translate this easy snip of C++ to Python
Clarence Gardner
clarence at netlojix.com
Sun Feb 4 16:11:57 EST 2001
More information about the Python-list mailing list
Sun Feb 4 16:11:57 EST 2001
- Previous message (by thread): Please translate this easy snip of C++ to Python
- Next message (by thread): Please translate this easy snip of C++ to Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, 04 Feb 2001, chris at onca.catsden.net wrote: >On 4 Feb 2001, Phlip wrote: [C debugging macro snipped] >Try this: > >def TRACE ( str ): > print "%s: %s" % ( str, eval(str) ) > >TRACE('y+z') >TRACE('strAnimals') > >Sorry... you /do/ need to put the parameters in quotes, so Python doesnt >try to evaluate them before calling TRACE You also need to provide the TRACE function with the caller's local namespace, or TRACE will, in general, get NameErrors. def TRACE(str, locals): print "%s: %s" % (str, eval(str, globals(), locals)) and call it like TRACE('y+z', locals()) (I know I'm stomping on a predefined function name in TRACE, but I have no problem with it in this case.) -- Clarence Gardner Software Engineer NetLojix Communications clarence at netlojix.com
- Previous message (by thread): Please translate this easy snip of C++ to Python
- Next message (by thread): Please translate this easy snip of C++ to Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list