python执行js文件

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import execjs,os
#执行本地自定义的js
print execjs.compile('function test(){'
               'return 5'
               '}'
               ''
               ''
               '').call("test")

#获取系统的路径
paths=os.path.dirname(__file__)
print paths
dir=paths+"/js/modules.js"
#执行*.js里的文件
print execjs.compile(open(dir).read().decode('utf-8')).call('add',3,4)

你可能感兴趣的:(python)