javascript - 如何运行从 Deno 导入的 Python 脚本?
问题描述
我目前正在尝试使用以下代码从 deno 后端运行 python 文件...
const cmd = Deno.run({
cmd: ["python", "python.py"],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output() // "piped" must be set
const outStr = new TextDecoder().decode(output);
const error = await cmd.stderrOutput();
const errorStr = new TextDecoder().decode(error);
cmd.close();
console.log(outStr, errorStr);
const resultsAlgorithm = outStr
console.log('This is a test, python result is...',outStr)
console.log('Finished')
该代码适用于'print(“Hello”)'等基本脚本,但无法在更复杂的脚本上运行导入,例如......
import pandas as pd # Changes call up name to pd
from yahoofinancials import YahooFinancials
from datetime import date, datetime, timedelta,time
Yahoo_Forex = pd.DataFrame()
Currency_Pair_Prices = pd.DataFrame()
print('Running')
def DataExtract(FileName, DataFrameName, DataFrameName_2, time_range, Interval, ColumnName):
print('Function started')
start = date.today() - timedelta(days=2)
end = date.today() - timedelta(days=time_range)
DataFrameName = pd.read_excel(FileName, header=None)
DataFrameName.columns = ColumnName
n = 0
for ticker in DataFrameName[ColumnName[0]]:
Currency_Pair = DataFrameName.iloc[n, 1]
Currency_Pair_Ticker = YahooFinancials(ticker)
data = Currency_Pair_Ticker.get_historical_price_data(
str(end), str(start), Interval)
Extracted_Data = pd.DataFrame(data[ticker]["prices"])
Currency_Close_Price = (Extracted_Data["close"])
DataFrameName_2[str(Currency_Pair)] = Currency_Close_Price
n = n+1 # 13
print(DataFrameName_2)
print("DataExtract Completed")
DataExtract("yahoo_Forex.xlsx", Yahoo_Forex, Currency_Pair_Prices,int(10), "daily", ["Ticker", "Pair", "Exchange"])
python代码自己成功运行,所以必须是deno的东西,但确定我需要改变什么,所以任何帮助都将不胜感激!
解决方案
推荐阅读
- html - 带有美化功能的 Vscode 不会缩进 django html 模板
- python - 自定义 pandas 排序功能
- javascript - 为元素内的 onclick 函数添加参数
- python - 更改包的全局变量
- azure - 将数据从 Azure Data Lake 移动到 Big Query
- javascript - 是否可以限制锚点HTML 5 下载属性中的文件扩展名?
- terraform - 詹金斯3-X | Terraform 销毁 | 错误 - 如果 EKS 未完全创建 |
- html - 居中社交媒体图标
- javascript - 在转换为我的本地时间之前发现网站的基本时区
- php - 无法安装 symfony/maker-bundle