PiotrDabkowski / Js2Py

JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
http://piter.io/projects/js2py
MIT License
2.45k stars 259 forks source link

Simple example - this must be my pilot error #303

Closed cworkschris closed 1 year ago

cworkschris commented 1 year ago

Hi, thank you for your project it might save me a lot of time dealing with some js files that are essentially data that I'd rather work with in python.

I reduced a js file to:

var myvar = String('hello')     // just using string in place of another function with dependencies for the moment

which I then converted to a python file

js2py.translate_file('short.js', 'short.py')

I then expected to be able to do this in ipython (following your example somewhat):

In [2]: import short                                                                                                         
In [3]: short.myvar                                                                                                          
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-bbe633c3c6a7> in <module>
----> 1 short.myvar

AttributeError: module 'short' has no attribute 'myvar'

I'm guessing I'm just a step away, but I wasn't able to filter all the intermediate variables needed for the conversion

worstperson commented 1 year ago

Your importing differently than the example, change import short to from short import short and it'll work.

cworkschris commented 1 year ago

much appreciated!