trapping a MySql warning

前端 未结 7 929
逝去的感伤
逝去的感伤 2020-11-29 23:59

In my python script I would like to trap a \"Data truncated for column \'xxx\'\" warning durnig my query using MySql.

I saw some posts suggesting the code below, but

相关标签:
7条回答
  • 2020-11-30 00:39

    If you want to trap it to ignore it see "Temporarily suppressing warnings" in Python's documentation:

    https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings

    import warnings
    
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        # Put here your query raising a warning
    

    Else, just read the doc about "warnings" module of Python, you can transform them into exception if you want to catch them later, etc... it's all here: https://docs.python.org/2/library/warnings.html

    0 讨论(0)
提交回复
热议问题