Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a problem with trying to start the program before it started fine and towards my login and such but now I get this error:


<pre>Traceback (most recent call last):
  File "/Users/tomas/Downloads/RegistroDeTienda/main.py", line 115, in <module>
    user = x["name"]
NameError: name 'x' is not defined. Did you mean: 'X'?
[Finished in 519ms with exit code 1]


what could be due? I have this


Python
conex3 = pymysql.connect(host='mysql-5706.dinaserver.com',
                             user='myadmin',
                             password='Fideo123.',
                             database='python',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.DictCursor)


cur3 = conex3.cursor()
verificarName = "SELECT * FROM clientes WHERE id = 1"
verificarPassword = "SELECT password FROM clientes WHERE id = 1"
cur3.execute(verificarName)

myresult = cur3.fetchall()
row6 = [item['name'] for item in myresult]
print (row6)
for x in myresult:
    print (x["name"])




####### VENTANA Tkinter #######

root = Tk()
root.title("Mostrar datos")
root.geometry("400x400")
imagen1=PhotoImage(file="logo2.png")
label1 = Label(root, image=imagen1)
label1.place(x=93, y=0)

x_ventana = root.winfo_screenwidth() // 2 - 300 // 2
y_ventana = root.winfo_screenheight() // 2 - 300 // 2

posicion = str(300) + "x" + str(300) + "+" + str(x_ventana) + "+" + str(y_ventana)
root.geometry(posicion)

root.resizable(0,0)



#frame = ttk.Frame(root, borderwidth=5, relief="ridge", width=200, height=100)
#frame.place(x=50, y=100)

user = x["name"]
password = x["password"]

ttk.Label(text="Usuario:").place(x=50, y=110)

ttk.Label(text="Contraseña:").place(x=50, y=165)

#### Entry Usuario ####
v1 = StringVar()
e1 = Entry(root, textvariable=v1, justify=CENTER)
e1.place(x=50, y=130, width=200, height=30)

#### Entry Password ####
v2 = StringVar()
e2 = Entry(root, textvariable=v2, show="*", justify=CENTER)
e2.place(x=50, y=185, width=200, height=30)


and more code but to simplify, this is where the error is thrown: user = x["name"]


Any additional information would be greatly appreciated


What I have tried:

<pre>Any additional information would be greatly appreciated
Posted
Updated 12-Jul-22 20:01pm

From that code fragment, we can't tell. But this may help: Python Scope[^]
 
Share this answer
 
As Griff suggested, x is out-of-scope.
After
Quote:
for x in myresult:
print (x["name"])
is executed, x is no more in scope and Python interpreter correctly complains.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900