I just read Campbell’s “Tips and Tricks” and came across a very useful one that everyone should be aware of.
Pseudo-breakpoints within Blender.
Ill copy it here:
1.3.6 Drop Into a Python Interpreter in You’re Script
In the middle of a script you may want to inspect some variables, run some function and generally dig about to see whats going on.
import code
code.interact(local=locals())
If you want to access both global and local variables do this…
import code
namespace = globals().copy()
namespace.update(locals())
code.interact(local=namespace)
The next example is an equivalent single line version of the script above which is easier to paste into you’re code: import(’code’).interact(local={k: v for ns in (globals(), locals()) for k, v in ns.items()})
code.interact can be added at any line in the script and will pause the script an launch an interactive interpreter in the
terminal, when you’re done you can quit the interpreter and the script will continue execution.
Very useful, but he doesn’t say how to quit the interpreter!
I tried the usual “quit()”, “exit()” but I can’t get out of it.
How?
i am not quit shure it its the same for all os,
but normaly closing is to close stdin/stdout
and thats done with (in linux):
strg-d
(ctrl-d)
a sample script … to test in the blender text-editor…
you can inspect the variable “name”
by simple typing “name” into the interactive console,
then ctrl-d to end it and the script runs on …
import bpy
name = "Cube"
def printlocation(name):
if name in bpy.data.objects:
o = bpy.data.objects[name]
print( o.location )
else:
print("no object found with name:", name)
# finish the interactive console in the console-window by pressing ctrl-d
__import__("code").interact(local={k: v for ns in (globals(), locals()) for k, v in ns.items()})
printlocation(name)
nice … than again Windows uses a “quite different way” … only to be different?
Here is a link to a table with codes and their uses.
Its the ASCII table and like some people still know, there are special sequences
for the communication and
ctrl-d = EOT, end of transmission (= closing the input)
while
ctrl-z = sub, substitute (… )