我必须从C#运行python文件。我设法运行python文件并使用以下代码获得结果:
using (StreamWriter sw = process.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(@"SET PYTHONPATH=C:\Users\protieax\entsoe-py-master\");
sw.WriteLine(@"python.exe C:\Users\protieax\entsoe-py-master\tests\test_data\request.py 31.12.2016 05.01.2017 datatype");
}
}
这一行:
sw.WriteLine(@"python.exe C:\Users\protieax\entsoe-py-master\tests\test_data\request.py 31.12.2016 05.01.2017 datatype");
我运行python文件并发送两个日期和一个类型的参数。但我不知道如何在python文件中访问这些参数。
python文件如下:
#import sys
#import logging
import os
import unittest
import pandas as pd
import bs4
from bs4 import BeautifulSoup
import entsoe.entsoe as ent
import xml.etree.ElementTree as ET
import json
global ENTSOE_SECRET_KEY
# set domain and timezone
domain = ent.DOMAIN_MAPPINGS['DE']
tmzone = ent.TIMEZONE_MAPPINGS['DE']
# initialize Enstoe class
ent_app = ent.Entsoe('a7a1b439-94b4-4eae-adf3-4cc57c82388a')
country_code = 'DE-AT-LU'
domain = ent.DOMAIN_MAPPINGS[country_code]
params = {'documentType': 'A44',
'businessType': 'B07',
#'contract_MarketAgreement.Type': 'A01',
'in_Domain': domain,
'out_Domain': domain,
}
# setup start and end time for request
start_date = [2017, 4, 8]
end_date = [2017, 4, 9]
start_tm = pd.datetime(start_date[0], start_date[1], start_date[2])
end_tm = pd.datetime(end_date[0], end_date[1], end_date[2])
# make request to entso-e
result = ent_app.query_price(country_code, start_tm, end_tm)