File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ """
3
+ This example demonstrates passing functions as arguments. Here, a
4
+ function is deinfed in JavaScript which expects a function as an
5
+ argument. Then that JavaScript function is executed from Python and
6
+ the Python `print` function is passed as an argument.
7
+ """
8
+
9
+ import pythonmonkey as pm
10
+ hello = pm .eval ("(func) => { func('Hello, World!'); }" )
11
+ hello (print ) # this outputs "Hello, World!"
12
+
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ """
3
+ This example returns a "HELLO, WORLD!" string created in JavaScript
4
+ using `pm.eval` for execting the JavaScript code.
5
+ The string is set to uppercase using JavaScript's `toUpperCase`
6
+ function.
7
+ """
8
+
9
+ import pythonmonkey as pm
10
+ hello = pm .eval (" 'Hello, World!'.toUpperCase(); " )
11
+ print (hello ) # this outputs "HELLO, WORLD!"
12
+
You can’t perform that action at this time.
0 commit comments