I translate some JS files using js2py library. I need to get, from the newly created python files, a variable which has the same name in every file.
with os.scandir(path=r'path_to_folder') as folder:
for file in folder:
if file.name.endswith('.js'):
new_name = os.path.basename(file) + ".py"
path = os.path.basename(file)
js2py.translate_file(path, new_name)
print("Translated")
print()
It works to translate every JS file into python, but I need those variables and importing from new_name('from new_name import var') doesn't work. Is there another way of getting those variables?
1 Answer 1
I found this on Js2Py GitHub.
>>> print(js2py.translate_js('var $ = 5'))
from js2py.pyjs import *
# setting scope
var = Scope( JS_BUILTINS )
set_global_object(var)
# Code follows:
var.registers(['$'])
var.put('$', Js(5.0))
Sign up to request clarification or add additional context in comments.
Comments
default
from new_name import *work?