用Python执行js文件代码并获取返回结果
生活随笔
收集整理的這篇文章主要介紹了
用Python执行js文件代码并获取返回结果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
js代碼(myjs.js):
/** @Title: This is a file for ……* @Author: JackieZheng* @Date: 2022-04-12 09:24:13* @LastEditTime: 2022-04-12 09:40:55* @LastEditors: Please set LastEditors* @Description:* @FilePath: myjs.js*/function hello(name, word) {console.log(word, name) } let para_name = process.argv[2] ?? 'Jackie' let para_word = process.argv[3] ?? 'Hello' hello(para_name, para_word)python代碼:
""" Title: python run js Author: JackieZheng Date: 2022-04-12 9:08:50 LastEditTime: 2022-04-12 09:38:12 LastEditors: Please set LastEditors Description: FilePath: runjs.py """ # -*- coding: utf-8 -*- import os# 執行node 運行myjs.js文件 后邊依次是要傳遞的參數 2,3,4…… command = os.popen("node myjs 杰克老師 您好") # print(command.read()) 防止亂碼建議用下邊的方式 result = command.buffer.read().decode("utf-8") command.close() print(result)運行結果:
E:\mini code\ (master -> origin) (cryptojs@1.0.0) λ python -u "e:\mini code\runjs.py" 您好 杰克老師總結
以上是生活随笔為你收集整理的用Python执行js文件代码并获取返回结果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 39所强基计划试点高校已全部公布招生简章
- 下一篇: mock.js使用