CKTIS / Python
type.__name__
Tento atribút triedy vracia jednoduché meno typu bez modulu a obklopujúcich tried.
Verzia: Python 3.14; repository image, production runtime not attested
Syntax
name = type(value).__name__Tento atribút triedy vracia jednoduché meno typu bez modulu a obklopujúcich tried.
type.__name__
Kvalifikované __qualname__ zachováva vnorenie. Rôzne typy môžu mať rovnaké jednoduché meno. Zmena mena používateľskej triedy neovplyvní jej identitu.
Najprv sa vypíše Item a Outer.Item, po premenovaní 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
Príklady
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))
Výsledok
Item Outer.Item Entry True
Najprv sa vypíše Item a Outer.Item, po premenovaní Entry True.