Search code examples
pythontranscrypt

How to use transcrypt in Python


I'm trying to transpile some simple examples, as the turtle tree example (https://github.com/bunkahle/Transcrypt-Examples/tree/master/turtle), using Pyhton 3.7.6 and transcrypt 3.7.16.

Basically, I'm just putting the .py within a folder and transcrypting from cmd doing:

"python -m transcrypt -n turtle_tree.py";

Everything seems to be ok, no errors are shown. After that, I changed the line 20 of the html file writting "_ _ target_ _/turtle_tree.js", as the output is not within _ _ javascript_ _ folder.

When I open the html it opens blank.

Can anybody figure out what I'm doing wrong? And if someone can provide me some documentation about this library, I would appreciate it.


Solution

  • Line 20 should be replaced, obviously within script tags, by:

     type="module"> import * as turtle_tree from './__target__/turtle_tree.js'; window.turtle_tree = turtle_tree;
    

    Then, from the cmd inside your folder, you have to open an http server:

    python -m http.server
    

    Finally, from your browser, you have to type:

    http://localhost:8000/turtle_tree.html
    

    It was as easy as following the Transcrypt docs v.v'

    2.2. Your first Transcrypt program: https://www.transcrypt.org/docs/html/installation_use.html#your-first-transcrypt-program