Utilizar raw_input en Python 2 para insertar datos en Sqlite3

31 views
Skip to first unread message

Mario Tapia

unread,
Jun 9, 2014, 1:04:55 AM6/9/14
to pythona...@googlegroups.com
Estimados me presento, mi nombre es Mario, vivo en Catamarca - Argentina, y hace muy poco descubrí el tremendo potencial de este lenguaje; quede fascinado con la simplicidad de el manejo de base de datos, vi muchos tutoriales sobre todos los temas pero no pude encontrar uno muy básico de Iinsertar Registros mediante raw_input en una base de datos Sqlite 3, ya que los que pude encontrar difieren entre si y no cumplen con ese objetivo "errores en la ejecución". Sin abusar de su buena voluntad dejo un código que se ajusta a mi necesidad pero no puedo ejecutarlo satisfactoriamente. Desde ya muchas gracias!

import sqlite3 as db #Import the SQLite module as db
import smtplib as mail #Importing the send email library as mail
from email.mime.text import MIMEText #Importing the text component of the mail library


#Getting the user to input the their data
username = raw_input("What would you like your username to be? ")
email = raw_input("What is your email address? ")
firstName = raw_input("What is your first name? ")
surname = raw_input("What is your surname? ")
age = raw_input("How old are you? ")
password = raw_input("What is your password?") #Encryption method will be added later
int(age) #Changing the age variable into an integer so it can be inputted into the database

#DB part
conn = db.connect('c:/Expedientes/apollo.db') #Connecting to the database
cursor = conn.cursor()
cursor.execute("INSERT INTO users VALUES(?, ?, ?, ?, ?, ?)",
            (username, email, firstName, surname, age, password)) #Inserting the user's data into the table

conn.close() #Closing the connection
Reply all
Reply to author
Forward
0 new messages