我在尝试清理代码时无法确定正确的实现,并且发现了一个似乎适合 For 循环的部分,但是,我收到以下错误:
Cannot use 'plot' in local scope.
Run Code Online (Sandbox Code Playgroud)
当尝试执行以下示例时:
a = 10
b = 5
for i = 1 to b
j = a * i
plot(highest(j), title="Resistance", color=b, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
Run Code Online (Sandbox Code Playgroud)
我原来的代码如下:
a=10
plot(highest(a*1), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*2), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*3), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*4), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*5), title="Resistance", color=color.green, linewidth=2, style=plot.style_line, transp=d, offset=-9999, trackprice=true)
Run Code Online (Sandbox Code Playgroud)
我最终希望绘图的数量(b 变量)可以从 0 …
我很难弄清楚如何从 Python 运行 NodeJS。我从 Python 运行 ShellScript 和从 ShellScript 运行 NodeJS 没有问题,但似乎无法从 Python 获取 NodeJS,我只得到以下输出:
b"
Run Code Online (Sandbox Code Playgroud)
这些是我的脚本的简化版本。
NodeJS 我正在尝试从 Python 中运行。
#!/usr/bin/env node
console.log("Hello " + process.argv[2]);
Run Code Online (Sandbox Code Playgroud)
这里是Python,使用Python3。
from datetime import datetime
import json
import os
import re
import sys
import subprocess
if __name__ == '__main__':
p = subprocess.Popen(['/Users/Brett/scripts/hello.js', 'Brett'], stdout=subprocess.PIPE)
out = p.stdout.read()
print(out)
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!非常感激。
编辑:我从命令行执行以下命令没有问题,因为“hello.js”是可执行的:
hello.js 'Brett'
Run Code Online (Sandbox Code Playgroud)
shell=true不修复它。
此外,我使用的是 macOS Catalina 10.15.5,因此我的 shell 是 zsh。
如果我添加node到命令的前面,我没有得到这样的文件或目录node,我尝试如下:
p = subprocess.Popen(['/Users/Brett/scripts/hello.js', 'Brett'], stdout=subprocess.PIPE)