How do I not raise a Python exception when converting an integer-as-string to an int

后端 未结 1 884
失恋的感觉
失恋的感觉 2021-01-23 09:57

I have some HTML I am trying to parse. There are cases where the html attributes alone are not going to help me identify the row type (header versus data). Fortunately, if my

相关标签:
1条回答
  • 2021-01-23 10:25

    Have you looked at the try statement?

    try:
        x = int(rowColumn[1][3].replace(',','').strip('$'))
    except ValueError, e:
        x = None # rowColumn[1][3] was not an integer
    
    0 讨论(0)
提交回复
热议问题