[DB-SIG] Beginner getting out...

Ignacio Guerrero ig_laselva@hotmail.com
Wed, 20 Mar 2002 17:10:18 -0300


At the risk of becoming a "Nonsense Threader" within the mail list I want to 
say something else. On my first answer to Arthur Albano I asked him what, 
I'm now aware, was a stupid question. I asked him the difference between SQL 
and MySQL. Marcus Lycka (sorry Marcus, I can't find the little circule that 
goes over the "a") tried to, mercifully, cover my misstake by stating that 
my question wasn't relevant (thanks for that).
Truth is, it was a stupid question. I hadn't even looked for an SQL nor 
MySQL FAQ.
Anyway, I still can't make run my script, and that's because I don't know 
how to add the Mysqldb module to it.
I'm just trying to do a simple (I believe) thing. To check whether a user 
and his password are in a table or not.
My script so far goes like this... comments are in spanish, uncomplete and 
is full of errors and bugs (I know... I'll fix them). Just try to get the 
picture:


#######################################################################
# Módulo:    passig.py
# Creado:    15-03-2002, por Ignacio Guerrero.
#######################################################################
# Función:   Este módulo permite registrar nuevos usuarios y sus
#            contraseñas o verificar los datos de usuarios existentes.
#
#######################################################################

import sys, string
from Tkinter import *

######### Definición de funciones ########################################

class rastUsr:
    "Verifica y, en caso de ser nuevo, Registra, identidad y clave de 
usuario"
    def confirmar(indicador, intentos=4, queja='Si o No'): # ¡Gracias, Guido 
Van Rossum!
        "Confirma con SI o con NO"
        while 1:
            respuesta = raw_input(indicador)
            if respuesta in ('s', 'si', 'sí', 'S', 'Si', 'Sí', 'SI'): return 
1
            if respuesta in ('n', 'no', 'nanay', 'nasti'): return 0
            intentos = intentos - 1
            if intentos < 0: raise IOError, 'Usuario rechazado'
            print queja

    def nuevoUsuario(id):
        "Ingresa nuevo nombre de usuario"
        usuario = raw_input(id)
        return usuario

    def nuevaClave(preg, repreg, nocomputa = 4, error = 'Las claves 
ingresadas difieren'): #Funciona
        "ingresa y confirma nueva clave de usuario"
        while clave == valid:
            clave = raw_input(preg)
            valid = raw_input(repreg)
            if clave != valid:
                print "Claves difieren"
            return clave

    def ingreseUsuario(id):
        "Ingresa nombre de usuario existente"
        usuario = raw_input(id)
        return usuario

    def ingreseClave(preg):
        "ingresa clave de usuario existente"
        clave = raw_input(preg)
        return clave

    def verificarId(usr, pwd): #Revisado, funciona bien.
        "Verifica si los datos ingresados están en el fichero"
        file = open('D:\\Programaci\363n\\misModulos\\passig.txt','r')
        while 1:
            x = file.readline()
            import string
            xdata = string.split(x,',')
            if xdata[0] == usr and xdata[1] == pwd: return 1
            if xdata[0] == usr and xdata[1] != pwd: return 2
            if xdata == ['']:
                file.close()
                return 0

    def escribirId(usr,pwd):
        file = open('D:\\Programaci\363n\\misModulos\\passig.txt','a')
        datus = usr + ',' + pwd
        file.write(datus)
        file.close()

    def registrarUsuario(preg):
        datos = raw_input(preg)
        return datos

######### Ejecución de Módulo 
###################################################

    def __init__(self)
        verif = self.confirmar("  ¿Nuevo usuario? (S/N)")
        if verif == 1:
            while verusr != 0:
                regu = self.nuevoUsuario("  Elija su nombre de usuario: ")
                regp = self.nuevaClave("  Ingrese su nueva contraseña: ","  
Reingrese su contraseña: ")
                verusr = self.verificarId(regu, regp)
                return verusr
            self.escribirId(datos)

        if verif == 0:
            usr = self.ingreseUsuario("  Ingrese su nombre de usuario: ")
            pwd = self.ingreseClave("  Ingrese contraseña: ")
            print "Bienbenido", usr

----------------------------------------------------------------------

Please, don't waste your time trying to fix it. I'll figure that out later. 
Just give my an example (a simple one) of how to connect with MySQL and add 
something to a table. That would do. Once I get the idea I'll see how to 
retrieve, modify, etc.
Thank you.
Ignacio

_________________________________________________________________
MSN Photos es la manera más sencilla de compartir e imprimir sus fotos: 
http://photos.latam.msn.com/Support/WorldWide.aspx