我是一名新的蟒蛇学习者。我创建了一个程序,并与sqlite db连接。但是当我运行程序时显示预期的缩进块错误。我怎样才能找出错误以及如何解决?请寻求您的帮助...我的代码示例如下。
def Book():
try:
c.execute("INSERT INTO {tn} ({vn}, {vm}, {vma}, {vnos}) VALUES (VehicleNo.get(), VehicleModel.get(), VehicleMake.get(), NoofSeat.get())".\
format(tn="Vehicle", vn="vnumver", vm="vmodel", vma="vmade", vnos="vnumofseat"))
except sqlite3.IntegrityError:
print('ERROR: ID already exists in PRIMARY KEY column {}')
c.execute("INSERT OR IGNORE INTO {tn} ({vn}, {vm}, {vma}, {vnos})) VALUES (VehicleNo.get(), VehicleModel.get(), VehicleMake.get(), NoofSeat.get())".\
format(tn="Vehicle", vn="vnumver", vm="vmodel", vma="vmade", vnos="vnumofseat"))
#Driver
try:
c.execute("INSERT INTO {tn} ({dn}, {dl}, {dp}) VALUES (DriverName.get(), LicenseNo.get(), Phone.get())".\
format(tn="Driver", dn="dname", dl="dlicence", dp="dphone"))
except sqlite3.IntegrityError:
print('ERROR: ID already exists in PRIMARY KEY column {}')
c.execute("INSERT OR IGNORE INTO {tn} ({dn}, {dl}, {dp})) VALUES (DriverName.get(), LicenseNo.get(), Phone.get())".\
format(tn="Driver", dn="dname", dl="dlicence", dp="dphone"))
#Customer
try:
c.execute("INSERT INTO {tn} ({cname}, {cadd}, {cphone}, {cfrom}, {cto}, {chire}, {cdate}, {crate}, {ctotalm}, {ctotalcost}) VALUES (DriverName.get(), LicenseNo.get(), Phone.get())".\
format(tn="Customer", cname="cname", cadd="caddress", cphone="cphone", cfrom="cfrom", cto="cto", chire="chire", cdate="cdate", crate="crate", ctotalm="ctotalm", ctotalcost="ctotalcost"))
except sqlite3.IntegrityError:
print('ERROR: ID already exists in PRIMARY KEY column {}')
c.execute("INSERT OR IGNORE INTO {tn} ({cname}, {cadd}, {cphone}, {cfrom}, {cto}, {chire}, {cdate}, {crate}, {ctotalm}, {ctotalcost})) VALUES (CustomerName.get(), Address.get(), Phone.get(), )".\
format(tn="Customer", cname="cname", cadd="caddress", cphone="cphone", cfrom="cfrom", cto="cto", chire="chire", cdate="cdate", crate="crate", ctotalm="ctotalm", ctotalcost="ctotalcost"))
答案 0 :(得分:0)
你需要在函数中缩进代码(第二行是你没有这样做的地方之一),这是一个例子:
def newFunction(x):
if (x < 5):
x = 2
Python对你如何安排代码更敏感,所以如果你习惯了JS,HTML等,你应该注意这一点。