Advertisement
teslariu

prod_db

May 29th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. import sqlite3
  6.  
  7. conn = sqlite3.connect("productos.sqlite")
  8.  
  9. cursor = conn.cursor()
  10.  
  11. cursor.execute("CREATE TABLE productos (codigo NUMERIC, nombre TEXT, precio NUMERIC)")
  12.  
  13. conn.commit()
  14.  
  15. datos = (
  16.     (1,"Teclado",1500),
  17.     (2,"Mouse",600),
  18.     (3,"Motherboard",15000),
  19.     (4,"Parlantes",3900)
  20.     )
  21.    
  22. for codigo, nombre, precio in datos:
  23.     cursor.execute("INSERT INTO productos VALUES (?,?,?)",(codigo, nombre, precio))
  24.  
  25. conn.commit()
  26.  
  27.  
  28. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement