Forum Archive

sys.argv when using the debugger

robnee

Is it possible to debug a program that requires command line arguments via sys.argv? This behaves differently when launched via Run vs Debug (after setting a breakpoint) and the command line arguments, when specified, are lost.

Import sys

Print(sys.argv)
JonB

I count this as a bug -- the debugger says the main script is pythonista_debugger with your script as the args, rather than honoring your args.

A workaround is to use run instead of debug: set your first breakpoint (either at prigram start, or where you know you want to poke around) using

import debugger
debugger.set_trace()

At that point breakpoints work normally.

robnee

Thanks for sharing this JonB. This technique looks handy. I will give this a try.