- This topic has 7 replies, 4 voices, and was last updated 5 years ago by .
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.
Home › Forum › SOFA › Programming with SOFA › [SOLVED] How to debug a python script in SOFA?
Tagged: debug
Hi,
I changed a .scn file to a python script and I did some changes inside the .py file. When I run the file in the terminal, I see my changes has not been applied. I know there are some errors in the file, but I receive no error in the terminal.
On the other hand, When I run .py in spyder, it gives me “ImportError: No module named Sofa”. How can I know what are the errors in my file? More generally, how can I debug a python script in SOFA?
kind regards,
Zahra
Hi Zahra,
In general, you can use the python debugger pdb
directly in the terminal
https://docs.python.org/2.0/lib/module-pdb.html
Or inside an IDE such as Spyder which supports pdb
as well
https://pythonhosted.org/spyder/debugging.html
I hope this will help,
Noura
Hi Noura,
Thank you, I try your hint.
Best,
Zahra
Python has a debugger , which is available as a module called pdb . It supports setting conditional breakpoints , stepping through the source code one line at a time, stack inspection, and more.
import pdb
msg = "this is a test"
pdb.set_trace()
print(msg)
Insert pdb.set_trace() anywhere and it will function as a breakpoint . When you execute the script by python test.py, you will in the debug mode.
Thank you @bennetcole for your valuable input.
And welcome on the SOFA forum!
WARNING
The forum has been moved to GitHub Discussions.
Old topics and replies are kept here as an archive.