简体   繁体   English

同时使用两个程序从 CSV 读取

[英]Reading from a CSV using two programs simultaneously

Good day.再会。 I am wondering if there is any way in which one can allow different programming languages to access a csv at the same time, I am using c# to get live stock market data, and then Python does calculations on this data where it then returns the data to the csv file to be read by c# again.我想知道是否有任何方法可以允许不同的编程语言同时访问 csv,我正在使用 c# 获取实时股票市场数据,然后 ZA7F5F35426B927411FC9231B5638 在此数据上返回此数据 27到 c# 再次读取的 csv 文件。 it works if I use multiple steps ie, collect historical data predict the historical data and read the historical data.如果我使用多个步骤,即收集历史数据预测历史数据并读取历史数据,它会起作用。 but when I try to do this in one step(live) I get the following error.但是当我尝试一步(实时)执行此操作时,我收到以下错误。

[Errno 13] Permission denied: 'CurrencyPair-Minute.csv'

I think this is the result of the file being used by the c# program.我认为这是 c# 程序使用文件的结果。 Which I opened with the following parameters我用以下参数打开

File.Open(fiName, FileMode.Open, FileAccess.ReadWrite, FileShare.Write);

I only close the data streams when the program stops and to the streams are continually open for reading and writing in the c# program.我只在程序停止时关闭数据流,并且在 c# 程序中持续打开数据流进行读写。 If I close the stream while the file is not being read or written the error I get is如果我在未读取或写入文件时关闭 stream,我得到的错误是

Crashed in (MethodName) with ArgumentException: Stream was not readable.

Also, this will not work since the Python program continually needs to check the file for updates.此外,这也不起作用,因为 Python 程序需要不断检查文件是否有更新。

Any help would be appreciated任何帮助,将不胜感激

Thank you谢谢

You should be able to run the python script from your C# file after fetching the data and writing to the csv and closing the csv file in C#. You should be able to run the python script from your C# file after fetching the data and writing to the csv and closing the csv file in C#. See here: How do I run a Python script from C#?请参阅此处: 如何从 C# 运行 Python 脚本? . .

The flow would be something like this:流程将是这样的:

C# C#

  • Fetch data获取数据
  • Write to csv写入 csv
  • Close file关闭文件
  • Call python script调用 python 脚本

Python Python

  • Do calculation做计算
  • Write to file写入文件
  • Close file关闭文件
  • Exit出口

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

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