我希望脚本从.csv文件读取,然后将我从控制台输入的内容附加到其中
def read():
j = 0#iterator
with open(FILENAME, "r", newline="") as file:
reader = csv.reader(file)
for row in reader:
product.insert(product[j], row)
j = j = 1
def write():
with open(FILENAME, "w", newline="") as file:
writer = csv.writer(file)
writer.writerows(product)
if keyboard.is_pressed('space'):
product_i = str(input("Input the PRODUCT name: "))
age_i = int(input("Input the AGE: ") )
price_i = int(input("Input the PRICE: ") )
new_list = [product_i,age_i,price_i]
product.extend([new_list])
with open(FILENAME, "a", newline="") as file:
writer = csv.writer(file)
writer.writerow(new_list)
print('Product has been added')
else:
pass