I’ve got an Nonetype value x, it’s generally a number, but could be None. I want to divide it by a number, but Python raises:
TypeError: int() argument must be a string or a number, not 'NoneType'
How can I solve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In one of the comments, you say:
If it’s your code, figure out how you’re getting
Nonewhen you expect a number and stop that from happening.If it’s someone else’s code, find out the conditions under which it gives
Noneand determine a sensible value to use for that, with the usual conditional code:…or even…
There’s no reason to automatically use
0here — solutions that depend on the “false”-ness ofNoneassume you will want this. TheDEFAULT_VALUE(if it even exists) completely depends on your code’s purpose.