英文:
how to get total row num in csv file
问题
我会为你翻译以下内容:
我想先获取总行数,如果行数符合要求,就从文件开头解析,但我已经知道上面的代码示例会获取到行数,但光标会停留在文件末尾。如何处理这个问题?
reader := csv.NewReader(fs)
reader.ReadAll()
除了上述方法之外,如果有的话,还可以提供其他获取总行数的方法。
英文:
I would like to get total row num first, if num meets need, will parse file from beginning, but I have known above code sample will get number but cursor is at the end of file. how to handle it?
reader := csv.NewReader(fs)
reader.ReadAll()
except for above way, can also provide other ways to get total rows if have
答案1
得分: 1
很抱歉,由 csv 包 实现的 RFC 4180 并没有定义任何元数据来跟踪总行数。当然,有些应用程序可能会存储这样的元数据,但在这种情况下,您需要使用自定义解析器来读取它们。
英文:
Unfortunately, RFC 4180 which is implemented by csv package does not define any metadata which would keep track of total rows. Of course some applications may store such metadata but in such case you would need a custom parser for reading them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论