S
S
Sergey Yavin2020-06-04 12:28:55
Python
Sergey Yavin, 2020-06-04 12:28:55

How to create table in db automatically in python?

There is a file with the names of groups in the university. I need to create as many tables as there are group names in the file. How to do this automatically in Python using sqlite3.

def init_db_groups(list_groups_name):
  conn = get_connection()
  c = conn.cursor()
  
  if force:
  c.execute('DROP TABLE IF EXISTS NAME_TABLE')

  c.execute('''
    CREATE TABLE IF NOT EXISTS NAME_TABLE(
    id_stud INTEGER NOT NULL PRIMARY KEY,
    number_zach INTEGER NOT NULL,
    password INTEGER NOT NULL)
  ''')


Is it possible to take execute in a loop and replace NAME_TABLE with values ​​from the list?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question