简体   繁体   中英

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. 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. 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. If I close the stream while the file is not being read or written the error I get is

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.

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#. See here: How do I run a Python script from C#? .

The flow would be something like this:

C#

  • Fetch data
  • Write to csv
  • Close file
  • Call python script

Python

  • Do calculation
  • Write to file
  • Close file
  • Exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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