Python:无法将列表输出生成到 f-string

Python: Trouble generating list output into f-string

我正在尝试找到一种方法来获取 csv 文件中的数据,然后 运行 通过循环为每一行创建输出。例如,此 csv 文件有 4 列,标题为姓名、颜色、年龄、性别。我写了这段代码来尝试实现它。

csv_file = input("Enter the location of your file.  ")
        with open(csv_file, 'r') as cat_example:
            cat_entries = csv.DictReader(cat_example)
            name = []
            color = []
            age = []
            gender = []
            for col in cat_entries:
                name.append(col["name"])
                color.append(col["color"])
                age.append(col["age"])
                gender.append(col["gender"])
            
            with open("cat_output_file.txt","w") as f:
                i = 0
                for (name,color,age,gender) in zip(name,color,age,gender):
                    while i < 10:
                        f.write(f"This cat's name is {name}, fur color is {color}, its age is {age} and its gender is {gender}.""\n")
                    
                        i = i +1
                    f.close()

我试图让输出如下。

This cat's name is Bob, fur color is orange, its age is 4, and its gender is male.
This cat's name is Tina, fur color is black, its age is 2, and its gender is female.
This cat's name is Frank, fur color is white, its age is 6, and its gender is male.
This cat's name is Samantha, fur color is purple, its age is 43, and its gender is female.

但是我得到的是这个输出,只是第一行重复了 4

This cat's name is Bob, fur color is orange, its age is 4, and its gender is male.
This cat's name is Bob, fur color is orange, its age is 4, and its gender is male.
This cat's name is Bob, fur color is orange, its age is 4, and its gender is male.
This cat's name is Bob, fur color is orange, its age is 4, and its gender is male.

我怎样才能最好地获得我正在寻找的结果?我尝试在 f-string 中执行 'pop',但没有成功。

非常感谢任何帮助!

我认为这应该有所帮助,您不需要 While 循环,这会导致结果重复

with open(csv_file, 'r') as cat_example:
    cat_entries = csv.DictReader(cat_example)
    name = []
    color = []
    age = []
    gender = []
    for col in cat_entries:
        name.append(col["name"])
        color.append(col["color"])
        age.append(col["age"])
        gender.append(col["gender"])
    
    with open("cat_output_file.txt","w") as f:
        for (name,color,age,gender) in zip(name,color,age,gender):
                f.write(f"This cat's name is {name}, fur color is {color}, its age is {age} and its gender is {gender}.""\n")
            
    f.close()