CKTIS / Python
Ključna riječ as
Veže ime prema okolnoj naredbi.
Verzija: Python 3.14; repository image, production runtime not attested
Sintaksa
import module as alias
with manager as value:
...Veže ime prema okolnoj naredbi.
Uvozni drugi naziv označuje uvezeni objekt, cilj with prima rezultat __enter__, a cilj except imenuje iznimku tijekom obrade. Uzorak as nakon uspjeha poduzorka hvata cijeli predmet.
Veze imaju različit vijek.
Primjeri
import math as numbers
from contextlib import nullcontext
with nullcontext(4) as qty:
value = numbers.isqrt(qty)
try:
raise ValueError("tag")
except ValueError as err:
label = str(err)
match [value, qty]:
case [2, _] as pair:
print(pair, label, "err" in globals())
Rezultat
[2, 4] tag False
Veze imaju različit vijek.