简体   繁体   English

使用 python 实时读取 csv

[英]Read csv in real time with python

I have a csv file that is writing some information on real-time with cicflowmeter.我有一个 csv 文件,它正在使用 cicflowmeter 实时写入一些信息。 Is there a way to catch every new row in the time that it is writed with a python script?有没有办法在使用 python 脚本编写时捕获每一个新行?

This problem can be solved without any python code.无需任何 python 代码即可解决此问题。 Just run something like tail -n0 -f logfile.csv | python3 program.py只需运行类似tail -n0 -f logfile.csv | python3 program.py tail -n0 -f logfile.csv | python3 program.py and have your program read from stdin like this: tail -n0 -f logfile.csv | python3 program.py并让您的程序从标准输入读取,如下所示:

import sys

for line in sys.stdin:
    # do something

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM