How to debug my python script

edited April 2018 in Python scripting
Hi

I am writing a python script but can not figure out how to do debug the script. I can insert print statements in the script but it becomes time consuming and not very effective. Is there a way to run the "pdb" like thing to step through the python script?

Thanks
enuinc

Comments

  • edited November -1

    If you are using the built in IDE (Press F5 to get it), then there are two toolbar buttons with tiny short or long green arrows -- to step into or over blocks. Just like pdb. You can also press F10 or F11.

  • edited November -1
    Thanks. However, I am using the "klayout -z -r test.py" type of way to run it. do you know how to use pdb in such usage mode?
  • edited November -1

    Hi enuinc,

    Basically for your kind of application, the Python API should be available as a plain Python module. That's not my main scope and raises some license questions, so I have not provided such a module yet.

    As of now, you can use the following trick:

    def mycode():
      ... put your code here ...
    
    # main entry point:
    if "debug_me" in globals():
      import pdb; pdb.run("mycode()")
    else:
      mycode()
    

    For normal operation, use

    klayout -z -r myscript.py
    

    for debugging, use

    klayout -rd debug_me=1 -z -r myscript.py
    

    Matthias

Sign In or Register to comment.