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)
5 Respuestas
+ 7
Om Yele ,
maybe you can > link < your code here?
+ 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!
+ 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('''
''')
0
int()
0
I fixed it with the help of keyword return and variable name