question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transpile Py to JS without running the code

See original GitHub issue

Is there a function in this library that can be called to transpile, but not run, some python code? The docs mention how the compiler works behind the scenes, but I haven’t been able to figure out how to replicate that process in order to avoid the eval called by brython.

Sorry if this is a silly question.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreQuentelcommented, Oct 8, 2018

In commit 346e87e910da66e870db94cf4e6506f2047a3a2a I have removed run_from_js and added python_to_js(src[, script_id]) which returns Javascript code ready to be eval’ed in a JS program.

It can run things like:

var src = "import datetime\n" +
    "for i in range(5):\n    print(i)\n" +
    "print(datetime.datetime.now())"
var js = __BRYTHON__.python_to_js(src)
js += "console.log('ok')"
eval(js)
1reaction
PierreQuentelcommented, Oct 6, 2018

Sorry, I misunderstood your request.

In the commit referenced above I have added a function __BRYTHON__.run_from_js(python_source[, script_id]), meant to execute Python from a Javascript program. script_id is the identifier of the Python program, defaulting to "__main__".

If it’s what you expect, can you try it with a few examples ? If it’s ok I will document it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why not transpile python to JS instead of running an interpreter?
I think there are people who write sort of syntax-y transpilers, but that's not really going to lead you down to nice code...
Read more >
Transcrypt - Python in the browser - Lean, fast, open!
The Transcrypt Python to JavaScript compiler makes it possible to program lean and fast browser applications in Python. Transcrypt applications can use any ......
Read more >
Transcrypt without java? - python - Stack Overflow
You can now compile without minification, so without Java by using the -n switch. So, try transcrypt -n hello.
Read more >
How to convert Python to JavaScript (and back again)
Before you dive in and start converting all of OpenStack to JavaScript, take heed: Jiphy is not about full-blown codebase conversion. Rather, ...
Read more >
TypeScript Compiling with Visual Studio Code
TypeScript is a typed superset of JavaScript that transpiles to plain ... select the Run Build Task command or press (Ctrl+Shift+B), you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found