I have a code with some variables and I need to find the same data from my mysql database.
from typing import Generator
from requests_html import HTMLSession
import pandas as pd
import numpy as np
from itertools import islice
import mysql.connector
from sqlalchemy import create_engine
horses = "Love Your Work (IRE)"
terrain = "Standard"
courses = "Doncaster"
distances = "1m"
pos1 = "1"
pos2 = "2"
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="horseracinguk"
)
#engine = create_engine("mysql+mysqlconnector://root:new_password@localhost/mydatabase")
engine = create_engine('mysql://root@localhost/mydbname?')
mycursor = mydb.cursor(dictionary=True)
mycursor.execute("SELECT * FROM mytable")
myresult = mycursor.fetchall()
for row in myresult:
if horses == row["horse"]:
if ((terrain == row["going"]) and (pos1 == row["pos"])):
pointsgoing1 = 2
horse = row["horse"]
terrain = row["going"]
course = row["course"]
distance = row["dist"]
position = row["pos"]
print(horse, terrain, course, distance, position, pointsgoing1)
I have a problem with this code, because when I am trying to find the same “terrain” variable (for example, “Standard”), my for loop returns not just rows with the word “Standard”, but also rows with this word inside that column (example: “Standard to Fast”, “Standard to Slow”), but I’d like to get just the row with the exact word “Standard”.
Any suggestion, please?
Thanks