CKTIS / Python
type.__name__
Atrybut klasy zwraca prostą nazwę typu, bez modułu ani otaczających klas.
Wersja: Python 3.14; repository image, production runtime not attested
Składnia
name = type(value).__name__Atrybut klasy zwraca prostą nazwę typu, bez modułu ani otaczających klas.
type.__name__
Nazwa kwalifikowana __qualname__ zachowuje ścieżkę zagnieżdżenia. Dwa różne typy mogą mieć tę samą prostą nazwę. Zmiana napisu nazwy klasy użytkownika nie zmienia tożsamości klasy.
Pierwszy wydruk odróżnia Item od Outer.Item, a po zmianie pojawia się Entry True.
class One:
class Item: pass
class Two:
class Item: pass
assert One.Item.__name__==Two.Item.__name__ and One.Item is not Two.Item
try: One.Item.__name__=3
except TypeError: pass
else: raise AssertionError
Przykłady
class Outer:
class Item: pass
item=Outer.Item()
print(type(item).__name__, type(item).__qualname__)
Outer.Item.__name__="Entry"
print(type(item).__name__, Outer.Item is type(item))
Wynik
Item Outer.Item Entry True
Pierwszy wydruk odróżnia Item od Outer.Item, a po zmianie pojawia się Entry True.