【发布时间】:2019-10-19 12:28:50
【问题描述】:
从 2.7 迁移后,我无法在 python 3 环境中获取行数。几次尝试后,返回的行数为 1。如何绕过 DeprecationWarning: 'U' mode is deprecated in python 3 ?
input_file = open("test.csv","rU")
reader_file = csv.reader(input_file)
value = len(list(reader_file))
在使用 python 3 的情况下,我尝试了以下方法,但我仍然坚持使用 1。
input_file = open("test.csv","rb")
reader_file = csv.reader(input_file)
value = len(list(reader_file))
【问题讨论】:
-
从
"rb"中删除"b"。 -
仍然给我一个 1
-
您能分享您的 CSV 文件的摘录吗?
-
>>> len(list(csv.reader(open(r'new.csv'))))为我工作。您的文件只有一行。
标签: python python-3.x csv migration