Python Print
In a Python ran externally it is opened a DOS console, and then it is possible to use the Python function print to show values in this console
But running code inside GiD this console doesn’t exists, and then this command cannot be used, except in case that the IDLE shell is opened and then the output of print is showed there.
Python print to file
To debug Python code it is always possible (inside and outside GiD) to print data of variables to a file, with something like this:
f=open('C:/temp/my_debug.txt','a') f.write('hello world\n') f.close()
Python show text with W
If Python is running in GiD then can call the Tcl GiD procedure called W that show text in a window
e.g.
import tohil tcl=tohil.import_tcl() a=5.2 tcl.W(a)
will show a GiD window with the value of the variable a
Note: tcl = tohil.import_tcl()
is a tohil module command that uses Tcl’s introspection capabilities to create Python object functions for each tcl proc and command, so that calling the Tcl procs looks very much like calling any Python function.
But the Python functions created depends on the procs existing when tohil.import_tcl()
is invoked. If the proc W is already not defined in Tcl during this call, the function tcl.W() won’t exists!!