Random Numbers
Explore how Transcrypt enables Python code to interact with JavaScript functions, including generating random numbers using JS Math.random, and how to debug your code with sourcemaps. Understand the transpilation process and how Python integrates with JavaScript runtime in a web browser.
We'll cover the following...
JS functions
At its most basic, Transcrypt allows Python code to call JavaScript functions and enables JavaScript functions to call Python functions. Let’s look at an example that explicitly does both.
This simple example is similar to the previous “Hello, World!” application we did:
Running the application
Use the following command to generate a JavaScript file from our Python code. But this time, let’s transpile the Python code with a few options:
The options in the Transcrypt command did a few things for us. First, the --nomin option causes the resulting JavaScript file not to be minified. This makes it a little easier to see how Transcrypt converts our Python ...