When I query my MySQL Database I get some extra characters that I don't want.
For example, instead of getting 165 I get (165), so, I tried the following in order to extract the number.
The problem is that instead of getting only the number, my code will print nothing, I can't find the reason. Any advice?
arr = ''
num = re.findall('\d+', arr)
mydb = mysql.connector.connect(
host="localhost",
user="root",
database="diff"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM val ORDER BY num DESC LIMIT 1")
myresult = mycursor.fetchall()
for x in myresult:
arr = x
print(arr)
myresultis empty. Use a debugger or print statements to see which statements are being executed.compilemethod inreto create a regex object. e.g.pattern = re.compile("\d+")and callpattern.findall(x)in the loop.