Is there any way to create different tables in SQLITE3 through the same python function?

0

I'm creating a bot in python through the python-telegram-bot library, and it works through commands. I know that through cursor.execute () I can create a table via python, but the real question is: is there a way to create different tables every time I call a function?

def criarnovarodada():   
     cursor.execute("""
CREATE TABLE rodada1 (id, rodada, texto, autor);
""")

Now, I created the cursor.execute, now I would like to create a table called "round2", but using the same function "criarnovarodada". How to proceed?

    
asked by anonymous 18.03.2018 / 14:28

1 answer

0

Just go back to the basics of programming and use function parameters:

def criar_nova_rodada(numero):
    cursor.execute("CREATE TABLE rodada{} (id, rodada, texto, autor);".format(numero))

So:

criar_nova_rodada(1)  # Cria rodada1
criar_nova_rodada(2)  # Cria rodada2

But you probably do not have to do that. Hardly an application needs this dynamic creation of tables. I recommend that you review the structure of your bank, as it is almost certain that you are not making the best solution.

    
18.03.2018 / 15:22