Python

Python 3 (MicroPython 1.26) nel Terminale: prompt interattivo, script e moduli (os, json, re, math, random...). Scrivi python, oppure python script.py.

versione 1.26.1 · Licenza: MIT · Sito del progetto

Python

A cosa serve

Python 3 nella versione MicroPython 1.26: lo stesso linguaggio, pensato per dispositivi piccoli. Qui hai il prompt interattivo, per provare al volo, e l'esecuzione di file .py con i loro moduli.

Come si usa

Comando Cosa fa
python apre il prompt interattivo (>>>)
python script.py esegue un file dalla cartella home
python script.py a b passa argomenti, letti in sys.argv
python -c "print(2**100)" esegue una riga di codice
python -m modulo importa ed esegue un modulo

Nel prompt i blocchi (for, def, if) continuano con ...: una riga vuota li chiude.

>>> sum(x * x for x in range(10))
285
>>> import json; json.dumps({"a": [1, 2]})
'{"a": [1, 2]}'

Moduli inclusi, pronti da importare:

I tuoi moduli vanno accanto allo script, in /lib o in /py (cioè /sdcard/home/lib, /sdcard/home/py).

Per uscire: EOF, oppure exit().

Limiti

È MicroPython, non CPython: niente pip, threading, socket, asyncio, subprocess. Ricorsione fino a circa 1000 livelli (come CPython), poi RuntimeError. Memoria: fino a 8 MB.

Nel Terminale

Python

Python 3 (MicroPython 1.26) in the Terminal: interactive prompt, scripts and modules (os, json, re, math, random...). Type python, or python script.py.

version 1.26.1 · License: MIT · Project site

Python

What it is

Python 3 as MicroPython 1.26: the same language, built for small devices. You get the interactive prompt, to try things out, and .py file execution with your own modules.

How to use it

Command What it does
python opens the interactive prompt (>>>)
python script.py runs a file from the home folder
python script.py a b passes arguments, read from sys.argv
python -c "print(2**100)" runs one line of code
python -m module imports and runs a module

At the prompt, blocks (for, def, if) continue with ...: an empty line closes them.

>>> sum(x * x for x in range(10))
285
>>> import json; json.dumps({"a": [1, 2]})
'{"a": [1, 2]}'

Built-in modules, ready to import:

Your own modules go next to the script, in /lib or in /py (that is /sdcard/home/lib, /sdcard/home/py).

To leave: EOF, or exit().

Limits

It is MicroPython, not CPython: no pip, threading, socket, asyncio, subprocess. Recursion up to about 1000 levels (like CPython), then RuntimeError. Memory: up to 8 MB.

In the Terminal