Uh oh!
There was an error while loading. Please reload this page.
Hey, I was wondering if there was a way to run one function, but not the whole js script. I've only seen examples where only one function is ran. Would there be a way to do the following ? functionhello(){return"hello";};functionworld(){return"world";};>>>evaluated.hello()
"hello">>>evalutated.world()
"world" |
Answered by
wiwichips
Jan 6, 2025
Replies: 1 comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi @novitae - Here's one way to do it using importpythonmonkeypythonmonkey.eval("""function hello() {return "hello";};function world() {return "world";};""")
print(pythonmonkey.globalThis.hello())
print(pythonmonkey.globalThis.world())which outputs A cleaner approach might be to use separate files and then use CommonJS to require the JavaScript file / module for use in your Python program
|
0 replies
Answer selected bynovitae
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @novitae - Here's one way to do it using
globalThisafter evaluating the functions.which outputs
A cleaner approach might be to use separate files and then use CommonJS to require the JavaScript file / module for use in your Python program
myjsfunctions.jsmy_python_file.py