jython 连接到 csv 文件
你好 我有一个读取 csv 文件的代码
import csv
d = csv.reader(open('C:/Documents and Settings/242481/My Documents/file.csv'))
for row in d:
print row
此代码返回 csv 文件中的所有行 有什么方法可以一次读取一行。 每次执行打印行时,我都需要获取下一行。 提前致谢 阿迪斯
Hi
I have a code to read the csv file
import csv
d = csv.reader(open('C:/Documents and Settings/242481/My Documents/file.csv'))
for row in d:
print row
This code returns all the rows in the csv file
Is there any way i can read one row at a time.
And each time i execute the print line i need to get the next row.
Thanks in advance
Aadith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该按照您的方式工作,但也许 EOL 字符不是您所使用的系统所期望的。尝试用 'rU' 打开它: open('file.csv', 'rU')
来验证它是否一次打印一行,您可以在行之间打印一个空行:
或暂停它:
对于您的其他代码,它应该是这样的:
始终关闭打开的文件。这是一个很好的做法,尽管并不总是严格必要的。 'file' 是一个 Python 类名。尽管您可以按照自己的意愿使用它们,但这样做可能会导致以后难以发现错误。
it should work the way you have it, but maybe the EOL characters are not what is expected for the system you're on. try opening it with 'rU': open('file.csv', 'rU')
to verify that it's printing one row at a time, you could print a blank line between rows:
or pause it:
For your other code, it should be something like:
Always close your open files. It's good practice, even though not always strictly necessary. And 'file' is a Python class name. Although you can use these any way you wish, doing so can lead to hard-to-find bugs later on.