python报错,execjs._exceptions.ProgramError: ReferenceError: aaaa is not defined

 
  

此为相关代码和报错.

python报错,execjs._exceptions.ProgramError: ReferenceError: aaaa is not defined_第1张图片 

在python运行JavaScript相关的库,出现报错.

源代码如下:

import execjs
import time
import random

node = execjs.get()
ctx = node.compile(open("./test.js",encoding="utf-8").read())
#wd = input("enter a key:")
wd = 'aaaa'
funcName = "md5(%s)"%wd
#print(funcName)

result = ctx.eval(funcName)
print(result)

前提:1)已装PyExecJS库,2)node.js运行环境.

检查后发现,犯了小错误,忘记在%s(即字符串)外加上’‘了,

修改后的代码:

import execjs
import time
import random

node = execjs.get()
ctx = node.compile(open("./test.js",encoding="utf-8").read())
#wd = input("enter a key:")
wd = 'aaaa'
funcName = "md5('%s')"%wd     # 此处加上'%s',代码运行成功⭐
#print(funcName)

result = ctx.eval(funcName)
print(result)

相关代码截图,且无报错

python报错,execjs._exceptions.ProgramError: ReferenceError: aaaa is not defined_第2张图片

没有报错,成功解译.

 

 总结:  要更加仔细地看代码.

你可能感兴趣的:(python小问题,大数据,javascript,python)