0

Convert nonetype to int

See there are two functions - todisplayfixedbike() , todisplaytotalbike() And i am storing values which are returning from above function. Value which are Stored in functions will not be constant . It will change continuously because it is connected with database Fixedbike1= todisplayfixedbike() Totalbike1= todisplaytotalbike() But Fixedbike1 and Totalbike1 are returning it's type as nonetype . Further i want to perform operation with integer value . So Conclusion , what should I do that function are returning value as nonetype instead of int as per i want , i want to convert that nonetype to int . So I can perform further operation. I tried to convert it by doing like this int(passing variable name)

3rd Aug 2022, 9:35 AM
Om Yele
Om Yele - avatar
5 Answers
+ 7
Om Yele , maybe you can > link < your code here?
3rd Aug 2022, 9:41 AM
Lothar
Lothar - avatar
+ 1
converting a Nonetype to int is not possible, they have very different meaning. I can see two solution: # use an if statement result = todisplaytotalbike() if result = None: result = 0 # or return an impossible value from todisplaytotalbike(), -1 is quite commonly used for this def todisplaytotalbike(): #some code here return -1 # instead of None I hope this helps you out but it will be easier if we could see some code example!
3rd Aug 2022, 11:20 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
def todisplaytotalbike(): popalltotalbike() myc=conn.cursor() print("Totalbike",totalbike) displaytotalbike="SELECT total_bike FROM BIKE_DETAILS" myc.execute(displaytotalbike) totalbikedata=myc.fetchall() totalbikedata=str(totalbikedata) for i in range(0,len(totalbikedata)): if totalbikedata[i].isnumeric(): totalbike.append(totalbikedata[i]) else: continue print("Totalbike",totalbike) totalbike1='' totalbike1=totalbike1.join(totalbike) totalbike1=int(totalbike1) print("Totalbike1: ",totalbike1) print("TOTAL NO OF BIKE AVAILABLE IN THE STOCK ARE: ",totalbike1) print(type(totalbike1)) print(''' ''')
3rd Aug 2022, 12:19 PM
Om Yele
Om Yele - avatar
0
int()
3rd Aug 2022, 10:47 AM
Chigozie Anyaeji 🇳🇬
Chigozie Anyaeji 🇳🇬 - avatar
0
I fixed it with the help of keyword return and variable name
3rd Aug 2022, 12:25 PM
Om Yele
Om Yele - avatar