
Print("It has been", now_fmt, "seconds since the epoch.") Now_int = int(datetime.timestamp(datetime.now())) Let's replace the py-script block in the original script with these two blocks:
PYTHON RUNNER WEB INSTALL
What if we want to install a package from PyPI and use that? PyScript has another tag, py-env, that specifies third-party packages need to be installed. If you wanted to modify the above script block to display the current time, you wouldn't need to do it any differently than you would in conventional Python: Standard library imports should just work in PyScript. Python's standard library is available in PyScript the same way you'd use it in regular Python: simply import and get to work. Scripts using Python's builtins alone are only somewhat useful. After that, Hello world should appear on the page. The runtime should remain cached on future loads but will still take a moment to activate. If you save this into a file and open it in a web browser, you'll first see a "loading" indicator and a pause, as the browser obtains the PyScript runtime and sets it up. In this example, stdout for the script gets directed into the div with the ID "out". If the script in the tags writes to stdout (as with a print) statement, you can direct where on the page to show the output by supplying an output property. Be aware of this if you use an editor that reformats HTML automatically it might mangle the contents of the py-script block and make it unrunnable.Īny Python code is evaluated once the PyScript components finish loading. Note that the code should be formatted according to Python's conventions for indentation, or it won't run properly. Python code is enclosed in the custom py-script tag. Among other things, it inserts notices to the user at the page's load time about what the page is doing-loading the Python runtime, initializing, and so on. The pyscript.css stylesheet is optional, but useful.


The script tag in the document's head loads the core PyScript functionality.
