在将CSV文件写入文件时进行读取 [英] Reading from a CSV file while it is being written to

查看:83
本文介绍了在将CSV文件写入文件时进行读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我开始之前,我知道这不是执行此操作的正确方法,但这是我即时访问所需数据的唯一方法.

So before I start I know this is not the proper way to go about doing this but this is the only method that I have for accessing the data I need on the fly.

我有一个在运行时将遥测数据写入.csv文件的系统.我需要在写入这些数据时查看其中的一些数据,但是这些数据并未以允许我执行此操作的方式进行广播.

I have a system which is writing telemetry data to a .csv file while it is running. I need to see some of this data while it is being written but it is not being broadcast in a manner which allows me to do this.

问题:如何从安全写入的CSV文件中读取信息.

Question: How do I read from a CSV file which is being written to safely.

通常,我将打开文件并查看值,但我希望能够编写一个python脚本,该脚本能够为我检查csv并报告最近写入的值,而不会影响系统的写入能力.文件.

Typically I would open the file and look at the values but I am hoping to be able to write a python script which is able to examine the csv for me and report the most recent values written without compromising the systems ability to write to the file.

我绝对访问系统或系统写入CSV的方式,我只能看到系统运行时CSV文件正在更新.

I have absolutely NO access to the system or the manner in which it is writing to the CSV I am only able to see that the CSV file is being updated as the system runs.

同样,我知道这不是正确的方法,但是您可以提供的任何帮助将非常有帮助.

Again I know this is NOT the right way to do this but any help you could provide would be extremely helpful.

这主要是在Windows环境中运行的

This is mostly being run in a Windows environment

推荐答案

您可以执行以下操作:

tailf csv_file | python your_script.py

并从sys.stdin

这篇关于在将CSV文件写入文件时进行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆