“ str”对象不可调用

时间:2019-11-22 04:35:25

标签: python sqlite

def name_table_():
    global date
    global routing_number_open_date
    global number_of_parts
    global name_table
    global list_of_parts
    global list_of_cost
    global routing_number_number
    global routing_number_close_date
    global dstatus
    global milage_in
    global milage_out
    global service_advisor_tag_number
    global work_phone
    global home_phone
    global vehicle_identification_number
    global deivery_date
    global in_service_date
    global year
    global make
    global model
    global body
    global color
    global licence_number
    routing_number_open_date = input("R/O Open Date? ")
    routing_number_number = input("R/O Number? ")
    routing_number_close_date = input("R/O Close Date? ")
    dstatus = input("dstatus? ")
    milage_in = input("Mileage In? ")
    milage_out = input("Mileage Out? ")
    service_advisor_tag_number = input("Service Adviser/Tag Number? ")
    work_phone = input("Work Phone? ")
    home_phone = input("Home Phone? ")
    vehicle_identification_number= input("Vehicle Identification Number? ")
    deivery_date = input("Delivery Date? ")
    in_service_date =input("In Service Date? ")
    year = input("Year? ")
    make = input("Make? ")
    model =input("Model? ")
    body = input("Body? ")
    color= input("Color? ")
    licence_number = input("license Number? ")
    c.execute("CREATE TABLE IF NOT EXISTS "("Name " + (str(d.month) + "/" + str(d.day) + "/" + str(d.year)), "routing_number_open_date,"
        "routing_number_number,"
        "routing_number_close_date,"
        "dstatus, "
        "milage_in,"
        "milage_out,"
        "service_advisor_tag_number,"
        "deivery_date,"
        "in_service_date,"
        "year,"
        "make,"
        "model,"
        "body,"
        "color,"
        "licence_number)"))
    conn.commit()


The full error is
Traceback (most recent call last):
  File "C:/Users/cabca/.PyCharmCE2019.2/config/scratches/scratch.py", line 324, in <module>
    name_table_()
  File "C:/Users/cabca/.PyCharmCE2019.2/config/scratches/scratch.py", line 134, in name_table_
    c.execute("CREATE TABLE IF NOT EXISTS "("Name " + (str(d.month) + "/" + str(d.day) + "/" + str(d.year)), "routing_number_open_date,"
TypeError: 'str' object is not callable

我一直在尝试根据输入的日期动态命名表,但我不能。我敢肯定,这只是一个简单的语法错误,或者应该是显而易见的错误,但是由于某种未知的原因,显而易见的错误对于我来说太难了。我已经犯了很多次错误,以至于我根本不明白问题出在哪里,我确定我所缺少的只是一些“”

1 个答案:

答案 0 :(得分:0)

看这行:

c.execute("CREATE TABLE IF NOT EXISTS "("Name " + (str(d.month) + "/" + str(d.day) + "/" + str(d.year)), "routing_number_open_date,"

关注此:

"CREATE TABLE IF NOT EXISTS "

这是一个字符串,对吗?并且您正在"CREATE TABLE IF NOT EXISTS "( .... )这样的行之后添加括号。

我不知道c.execute如何接受参数,但是如果它接受一个字符串,请在字符串之间添加+。如果需要多个参数,请添加,