Trying to python takes a variable in to Create Table
Question: I'm trying to python takes a variable when it ask for the data base name but
it does not work this is my code, I do not know whan I'm doing wrong.

any idea ?

    
    
    #!/usr/bin/python
    # -*- encoding: utf-8 -*-
    
    import MySQLdb
    
    name_db = raw_input('Type Data Base Name : ')
    
    bd = MySQLdb.connect("localhost","root","9090i","clientes" )
    
    cursor = bd.cursor()
    
    sql = "CREATE TABLE name_db (NOMBRE  CHAR(20) NOT NULL, APELLIDO CHAR(20), EDAD INT, SEXO CHAR(1), SALARIO FLOAT )"
    
    cursor.execute(sql)
    
    bd.close()
    


Answer: Change

    
    
    sql = "CREATE TABLE name_db (NOMBRE  CHAR(20) NOT NULL, APELLIDO CHAR(20), EDAD INT, SEXO CHAR(1), SALARIO FLOAT )"
    

to

    
    
    sql = "CREATE TABLE {name} (NOMBRE  CHAR(20) NOT NULL, APELLIDO CHAR(20), EDAD INT, SEXO CHAR(1), SALARIO FLOAT )".format(name = name_db)
    

The {name} is Python's syntax for string replacement so this should create a
constant SQL String that has the value you typed in substituted for the table
name.

To check this it's a good idea to print out the SQL before you execute it.
That makes it easier for you to see why the code isn't working.

