Home > Software design >  How to print the result of a class without the class name?
How to print the result of a class without the class name?

Time:10-24

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?

CodePudding user response:

The name attribute of the Enum

print(StaticTileType(4).name)

Result:

WALL

CodePudding user response:

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

obj= StaticTileType(4)

print(obj.DOOR)

  • Related