Python csv。读者:我如何返回到文件的顶部?
16lz
2021-01-22
When I'm moving through a file with a csv.reader, how do I return to the top of the file. If I were doing it with a normal file I could just do something like "file.seek(0)". Is there anything like that for the csv module?
当我使用csv文件时。读者,我如何回到文件的顶部。如果我用一个普通的文件,我可以做一些类似“file.seek(0)”的操作。csv模块有类似的东西吗?
Thanks ahead of time ;)
(谢谢!)
2 个解决方案
#1
64
You can seek the file directly. For example:
你可以直接查找文件。例如:
>>> f = open("csv.txt")
>>> c = csv.reader(f)
>>> for row in c: print row
['1', '2', '3']
['4', '5', '6']
>>> f.seek(0)
>>> for row in c: print row # again
['1', '2', '3']
['4', '5', '6']
更多相关文章
- 读取python中的unicode文件,该文件以与python源代码相同的方式声
- python 操作excel 读写同一个文件
- Python学习笔记(基础篇)_014_GUI模块 easygui的使用
- 如何使用pip安装Python MySQLdb模块?
- 使用自定义qemu二进制文件与libvirt失败?
- 在模块和/或包中组织Python类
- 【python coding 1:网络检测】ping本地文件里的ip地址
- 如何输出NLTK块到文件?
- Python/模块与包之模块