Search code examples
pythonbashpython-2.7debuggingrhel

python + how to debug python script on linux as bash with -x


we are running some python scripts on linux

since python are sometimes difficult to understand in case of failure then need to find a good way of debugging

for example from bash world its bash -x

what is the equivalent way for python ?

example without python debug

 python /lpp/airflow/.sec/security.py get_connection_string rmq
Traceback (most recent call last):
  File "/lpp/airflow/.sec/security.py", line 105, in <module>
    get_connection_string(sys.argv[2])
  File "/lpp/airflow/.sec/security.py", line 58, in get_connection_string
    pass_hash  = open(rmq_pass_file, 'r')
IOError: [Errno 2] No such file or directory: '/lpp/airflow/.sec/rmq_pass'

Solution

  • I usually debug code python by VSCode. And if having some code are too difficult, I can run this line throught terminal. This is my way to see what happends in my program.