CKTIS / Python
__import__()
Uruchamia mechanizm importu dla nazwy podanej napisem.
Wersja: Python 3.14; repository image, production runtime not attested
Składnia
__import__(name, globals=None, locals=None, fromlist=(), level=0)Uruchamia mechanizm importu dla nazwy podanej napisem.
Przy xml.etree pusty fromlist zwraca pakiet najwyższego poziomu xml. Niepusty fromlist zwraca xml.etree i może wskazywać atrybuty lub podmoduły.
Domyślny level=0 wybiera import bezwzględny, a dodatni poziom oznacza import względny wobec pakietu.
top = __import__("xml.etree")
leaf = __import__("xml.etree", fromlist=["ElementTree"])
assert top.__name__ == "xml" and leaf.__name__ == "xml.etree"
Przykłady
top = __import__("xml.etree")
leaf = __import__("xml.etree", fromlist=["ElementTree"])
print(top.__name__, leaf.__name__)
Wynik
xml xml.etree
Domyślny level=0 wybiera import bezwzględny, a dodatni poziom oznacza import względny wobec pakietu.