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']

更多相关文章

  1. 读取python中的unicode文件,该文件以与python源代码相同的方式声
  2. python 操作excel 读写同一个文件
  3. Python学习笔记(基础篇)_014_GUI模块 easygui的使用
  4. 如何使用pip安装Python MySQLdb模块?
  5. 使用自定义qemu二进制文件与libvirt失败?
  6. 在模块和/或包中组织Python类
  7. 【python coding 1:网络检测】ping本地文件里的ip地址
  8. 如何输出NLTK块到文件?
  9. Python/模块与包之模块

随机推荐

  1. android 9.0默认launcher
  2. Android Tutorial: Optimizing for Phone
  3. android 触摸手指动作放大和缩小图片
  4. Android联系人数据库全
  5. Android知识点剖析系列:深入了解layout_we
  6. Android画图Path的使用
  7. Android quota
  8. Android实现文件上传功能
  9. Android textView字间距自定义LetterSpac
  10. Android App Development: Using Themes