我很难将format_column中的值传递给create_table方法:
class Sqlite_driver:
def __init__(self, db_name, table_name, columns):
self.db_name = db_name
self.table_name = table_name
self.columns = columns
def format_column(self, columns):
Sqlite_Allowed_Types = {
"TEXT":"2500",
"NUMERIC":"250",
"INTEGER":"250",
"REAL":"100",
"BLOB":"100",}
table_columns = []
for k,v in columns.items():
table_columns.append(k+" "+v+" "+"("+Sqlite_Allowed_Types [v]+")")
return(table_columns)
def create_table(self,table_name, columns):
'''
creates the Sqlite3 table and columns.
table_name expects a string
columns expects a dictionary
example :
table_name = "Customer"
columns ={"Name":"TEXT"}
'''
format_column(columns)
query = """CREATE TABLE """+ table_name+""" """+table_columns+""");"""
我认为这是由于实例化问题,但我不确定。
答案 0 :(得分:2)
在调用create_table
方法
format_column
方法中实际指定返回值
table_columns = self.format_column(columns)
query = """CREATE TABLE """+ table_name+""" """+table_columns+""");"""