Serveira
Serveira

Reputation: 51

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?

Upvotes: 0

Views: 56

Answers (2)

Aadesh kale
Aadesh kale

Reputation: 248

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

obj= StaticTileType(4)

print(obj.DOOR)

Upvotes: 1

rdas
rdas

Reputation: 21275

The name attribute of the Enum

print(StaticTileType(4).name)

Result:

WALL

Upvotes: 2

Related Questions