name 'cursor' is not defined.Python27

0

Hello, how I have a doubt which in the script I have, I defined the connection and the cursor but when running that code fragment gives me the error name 'cursor' is not defined.

I hope to explain.

In the first line of the function I make the connection to the database and in the next line I am reading a csv file which is inside the folder since that file is necessary to read it, the information in this file is not is inside the database, in the next line I create the cursor to be able to extract the information from the ba which is the one that I am trying to access. I hope you can help me.. Thanks in advance!!

Here is the code that generates the error

def test():

        db = MySQLdb.connect(host="localhost", user="root",passwd="1234",db="Horario")
        cursor = db.cursor() #executing conecction


        courses = []
        tablacourses=pd.read_csv('courses.csv',header=1,error_bad_lines=True)

        for c in tablacourses.itertuples():
            courses.append( c[1] )

        profs = []
        cursor.execute("SELECT * FROM sised_profesor WHERE estatus='ACTIVO'") # execute  query
        datos = cursor.fetchall() # get data
        tablaDatos = pd.DataFrame(list(datos),columns=titulos)

        for p in tablaDatos.itertuples():
            profs.append(p[1])

        times = []

        cursor.execute("SELECT id_horario_docencia FROM sised_horario_docencia ORDER BY GROUP ") # execute query
        datos = cursor.fetchall() # get data
        tablaDatos = pd.DataFrame(list(datos),columns=titulos) # save data to dataframe
        for t in tablaDatos.itertuples():
            times.append(p[1])

        rooms = []
        cursor.execute("SELECT id_espacio FROM sised_espacio ORDER BY GROUP ID")   # execute query 
        datos = cursor.fetchall() #  get data
        tablaDatos = pd.DataFrame(list(datos),columns=titulos) # save data to dataframe

        for r in tablaDatos.itertuples():
            rooms.append(r[1])
    
asked by Shadow 14.03.2018 в 04:28
source

0 answers