我收到错误->
Traceback (most recent call last):
File "C:\Users\REJI\Desktop\project\the project\book_store.py", line 346, in <module>
sale()
File "C:\Users\REJI\Desktop\project\the project\book_store.py", line 321, in sale
read_sale()
File "C:\Users\REJI\Desktop\project\the project\book_store.py", line 217, in read_sale
print(body%(str(row[0]),row[4][0:20],str(row[2])[0:15],str(row[1]),str(row[3])))
TypeError: 'NoneType' object is not subscriptable
对于此python->
def read_sale():
qs='''select s1.*,book_title from sale s1, bookmaster b1
where s1.book_no=b1.book_no order by s1.book_no'''
cur.execute(qs)
data=cur.fetchall()
head='''\
All Sales
+-------+--------------------+------------+----------+----------+
|Book No| Title |Date of sale| Quantity | Price |
+-------+--------------------+------------+----------+----------+'''
body='''\
|%7s|%20s|%12s|%10s|%10s|
+-------+--------------------+------------+----------+----------+'''
print(head)
for row in data:
print(body%(str(row[0]),str(row[4])[0:20],str(row[2])[0:15],str(row[1]),str(row[3])))
并且用于在此mysql表中的列中输入值->
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| book_no | int(30) | YES | | NULL | |
| quantity | varchar(15) | YES | | NULL | |
| sdate | date | YES | | NULL | |
| price | int(40) | YES | | NULL | |
| title | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
并且如果我将某些代码更改为str,我得到以下结果,我不希望列标题和数量的信息不显示任何信息,我希望它们显示mysql表中存在的某个值。] >
Enter your choice 1-51 All Sales +-------+--------------------+------------+----------+----------+ |Book No| Title |Date of sale| Quantity | Price | +-------+--------------------+------------+----------+----------+ | 147| **None** | 2019-11-20| **None**| 50| +-------+--------------------+------------+----------+----------+ sale Menu`enter code here` ----------------- 1.To read_sale 2.To add_sale 3.TO Exit and return to main menu
因此,如果可以的话,请帮助我,对你的帮助表示感谢谢谢
我收到错误->追溯(最近一次通话):文件“ C:\ Users \ REJI \ Desktop \ project \ theproject \ book_store.py”,行346,位于[[sale()文件中:\ Users \ REJI \ Desktop \ project \ ...
title = NULL
,有些销售有quantity = NULL
。您需要先检查这些内容,然后再尝试格式化它们。