[英]How can I make a python code with the csv module that change each row at respective iteration
Suppose there is a csv file named 'example.csv':假设有一个名为“example.csv”的 csv 文件:
a, b, c a, b, c
a, b一,乙
a, b一,乙
a, b一,乙
a, b一,乙
I want to change all rows of this csv file to be 'a, b, c' using a Python code with csv module, however suppose that this code is heavier than my computer's computing power so, perhaps, the program may be abruptly interrupted (Probably, the user stop the program).我想使用 csv 模块的 Python 代码将这个 csv 文件的所有行更改为“a,b,c”,但是假设这个代码可能比我的计算机突然中断可能,用户停止程序)。 In this case, the progress of this csv must be saved.
在这种情况下,必须保存这个 csv 的进度。 For example, if the code did two iterations and terminated, then the original 'example.csv' or copied version 'copied_example.csv' should be:
例如,如果代码进行了两次迭代并终止,那么原始的“example.csv”或复制的版本“copied_example.csv”应该是:
a, b, c a, b, c
a, b, c a, b, c
a, b, c a, b, c
a, b一,乙
a, b一,乙
You could in theory loop through the csv and save changes in every loop.理论上,您可以循环通过 csv 并在每个循环中保存更改。 Instead of using a csv module, you could use normal open() and then write() in a loop.
除了使用 csv 模块,您可以使用普通的 open() 然后在循环中使用 write()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.