I'm put my question here, but first I searched this entire site and didn't find the correct answer for it.
I'm a noob in Python and PyGTK.
here is my code:
from PyQt4 import uic
from PyQt4 import QtGui
from PyQt4 import QtCore
import MySQLdb
import sys,os
###delete the most of the code... left that i think is needed ... (thanks ... for the comment about code lenght) ###
def basedatos(self):
db_host = 'localhost'
usuario = 'root'
clave = ''
base_de_datos = 'toco_bdd'
db = MySQLdb.connect(user=usuario,passwd= clave,db= base_de_datos,unix_socket="/opt/lampp/var/mysql/mysql.sock")
def chequeouser(self):
passwdcheck = txt_password.text()
usuariover = txt_usuario.text()
datosLogin = "SELECT * FROM t_usuarios WHERE id_usuario = usuariover AND password = 'passwdcheck"
#para Futura Referencia - QtGui.QMessageBox.warning(self, "hola", "tu nombre de usuario es:"+usuariover+"y tu password es" + passwdcheck,QtGui.QMessageBox.Ok)
datosLogin = "SELECT * FROM t_usuarios WHERE id_usuario = 'usuario' AND password = 'password'"
cursor = db.cursor()
cursor.execute(datosLogin)
app = QtGui.QApplication(sys.argv)
#window.resize( 350,210)
#window.move(450,250)
#window.setWindowTitle("TM Administrador - Login")
#window.show()
loginit = entrar()
loginit.show()
sys.exit(app.exec_())
and I'm getting this error:
cursor = db.cursor() NameError: global name 'db' is not defined
You've defined 'db' inside of def basedatos(self): so when you try to access that inside of the other functions it's not defined there so you get that error. You could define that globally to resolve that error. I'm a noob myself, so not sure how 'pythonic' that is, but that's why you're getting the error anyway.