From: Ian P. <ian...@er...> - 2011-11-07 11:37:51
|
Hi Enrico, Thanks for update. Excellent idea, and certainly makes reading errors back easier. The examples are in Labview 2010. If possible, please can you convert to Labview 2009? Best Regards Ian ________________________________________ From: Enrico Segre [enr...@we...] Sent: 02 November 2011 15:03 To: 'LabPythonUsers Mailing List' Subject: [LabPython-Users] R: comments on labpython (WORKING with LV2010/python 2.7.1) >Issue (2) makes it very diffuclt to debug any code, in particular code that works ok in python IDLE but not in Labview (+ labpython). >I also find the lack of feedback when running a labpython script also limiting (i.e. Print statement doesn't output to anywhere). It would be great if the print command >and error information could be displayed in a dos window or better in a dedicated window in labview, and even better if this was updated in real time. >To overcome the issues above, I now use the following as part of my python code. > >import sys ># Re-direct stdout >... I've elaborated a little on your idea, and send stdout and stderr to python strings with the following variation: import sys from StringIO import StringIO import traceback # Re-direct stdout old_stdout = sys.stdout sys.stdout = stdoutcapture = StringIO() # Re-direct stderr stderrstring="" try: # [insert code here] except: stderrstring=traceback.format_exc() print "Unexpected error:", sys.exc_info() sys.stdout = old_stdout stdoutstring=stdoutcapture.getvalue() After the Python Execute script node, I can pull the variables stdoutstring and stdoutstring into labview, and see the result. No realtime, but helps. No hassle of handling files in changing directories and reading them back into LV. Attached an llb containing two small convenience vi's - one for wrapping the python script, the other for reading back the variables into LV strings. Enrico |