我有缓冲区json,并在nodejs中写入python this:
const python = spawn("python", ["index.py"]);
//label = ["a","b","c","d"]
let label = Buffer.from(JSON.stringify(label)); //<-----------------HERE
python.stdin.write(label); //<-----------------HERE
python.stdin.end();
我在python中读到一行:
label = sys.stdin.readlines()
print(label)
#OUTPUT : ['["a","b","c","d"]']
如何将is['["a","b","c","d"]']转换为python中的数组以供使用?谢谢
使用json.load
:
import json
label = json.load(sys.stdin)