简体   繁体   中英

How to print the result of a class without the class name?

The following class declares variables and their values.

class StaticTileType(Enum):
    CHASM = 0
    EMPTY = 1
    GRASS = 2
    EMPTY_WELL = 3
    WALL = 4
    DOOR = 5

print(StaticTileType(4))

This code prints StaticTileType.DOOR . How can I print/return DOOR only, without the module name?

The name attribute of the Enum

print(StaticTileType(4).name)

Result:

WALL

You may need to create object of that class and access values

obj= StaticTileType(4)

print(obj.DOOR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM