Locating the line number where an exception occurs in python code

前端 未结 10 2045
长情又很酷
长情又很酷 2020-12-16 18:55

I have a code similar to this:

try:
  if x:
      statement1
      statement2
      statement3
  elif y:
      statement4
      statement5
      statement6
          


        
10条回答
  •  温柔的废话
    2020-12-16 19:03

    You should wrap the statements you care about more tightly. Extracting the line number from the traceback is going to be involved and fragile.

提交回复
热议问题