【问题标题】:Printing a csv 'none' error打印 csv 'none' 错误
【发布时间】:2013-02-10 18:52:53
【问题描述】:

尝试打印 csv,但我不断收到错误“无”我想简单地列出 csv 的内容。我有两天,周六周日

【问题讨论】:

  • 你的函数没有 return 任何东西,所以它打印 None
  • 请修正缩进,否则可能很难判断问题到底是什么。

标签: python search csv


【解决方案1】:

您的 friday 函数没有返回任何内容。

如果你想打印文件中的数据,你必须遍历它

csvFile = csv.reader(open('friday.csv','rb'))

从 csv 文件读取的每一行都作为字符串列表返回。

for line_list in csvFile:
  # do something with the dat

【讨论】:

    【解决方案2】:

    fridaysaturday 方法不包含任何 return 语句。默认情况下,Python 在到达函数末尾而没有遇到return 语句时返回None

    添加return(以及实际读取文件的代码),如下所示:

    def friday():
       with csv.reader(open('friday.csv','rb')) as csvFile:
           return '\n'.join(' - '.join(csvFile))
    

    【讨论】:

      猜你喜欢
      • 2019-04-29
      • 1970-01-01
      • 2022-12-03
      • 2021-11-12
      • 2021-12-01
      • 1970-01-01
      • 2021-09-30
      • 2021-04-24
      • 1970-01-01
      相关资源
      最近更新 更多