我想让脚本读取.csv文件,然后通过控制台附加新输入

时间:2019-06-11 06:46:32

标签: python

我希望脚本从.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

0 个答案:

没有答案