Home > Software design >  Print left side of a split number. AttributeError: 'list' object has no attribute 'sp
Print left side of a split number. AttributeError: 'list' object has no attribute 'sp

Time:10-07

This code prints as output [8.1]. I would like to print 8

cursor.execute ('SELECT date FROM Archive WHERE product =?', (element,))
values3 = [row [0] for row in cursor]
#values3 is [8.1]

I have used, but i get error AttributeError: 'list' object has no attribute 'split'

a = values3.split('.')
b = a[0]
print(b)

Can you help me please? Thank you

CodePudding user response:

Try this: a = values3[0] a = str(a).split(".")[0]

CodePudding user response:

First convert it from a list to a int:

values3 = values3[0]

This will give: values3 = 8.1.

then use the round function to round the number:

num = round(values3).

CodePudding user response:

value3 is a list. Convert it to int and take the floor if you just want the leftside of the number.

import math as m
print(m.floor(values3[0]))
  • Related