-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_JS_from_Python.py
More file actions
34 lines (28 loc) · 927 Bytes
/
run_JS_from_Python.py
File metadata and controls
34 lines (28 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---
#Project Name : RUN JAVASCRIPT FROM PYTHON
#Author: Priya Mondal
---
#Module Name: Js2Py --> Used to translate any valid JavaScript(ECMA Script 5.1) to Python. Acts as a Javascript Interpreter. Does not
# have dependencies -uses only standard python library. Translation is fully Automatic.
# LIMITATIONS OF THIS Module:
# --> Strict Mode is ignored.
# --> With statement is not supported.
# --> Indirect call to eval will be treated as direct call to eval(hence alwyas evals in local scope)
#import the necessary package
import js2py
#example 1
# A JS Command
js1 = 'console.log("Hello World!")'
res1 = js2py.eval_js(js1)
# print the result
res1
# -------------------------------------------------
# example 2
js2 = '''function add(a,b){
return a+b;
}'''
#store the function. Taking User input
a = int(input('Enter a num: '))
res2 =js2py.eval_js(js2)
#print the result
print(res2(a,3))