【问题标题】:How do I get a Python program to continuously input new information from a CSV spreadsheet?如何让 Python 程序从 CSV 电子表格中不断输入新信息?
【发布时间】:2022-07-13 23:52:03
【问题描述】:

如果我有这样的程序需要用户输入信息:

first_name = input("Enter First Name: ")
last_name = input("Enter Last Name: ")

如何使用包含名字和姓氏的 CSV 表中的数据来连续输入和循环数据,为我提供所有名字的输出?

换句话说,我希望我的程序从我的 CSV 列表中输入每个人的姓名并给我单独的输出(这是程序为他们计算的数字),这样我就不需要手动完成所有操作。

print(output)
Adam Smith, 378
John Smith, 673
Jane Doe, 289
...

这可能吗?非常感谢您的帮助 - 谢谢!

【问题讨论】:

    标签: python


    【解决方案1】:

    你可以使用 Python csv 模块:

    import csv
    
    path_to_file = ...
    file_content = csv.reader(path_to_file)
    
    for row in file_content:
        print(row)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 2017-10-12
      相关资源
      最近更新 更多