I'm searching for a collection
that can be used to store multiple constants and also can be used to get a list of them?
EDIT: It does not have to be constants, it can be variables.
I want to get a value this way:
Constants.first_one
But also get a list of values like:
Constants.values
Which returns something like:
['First one', 'Second one' .... ]
Using a class
and class attributes
is good for the first usage but not for the second one:
class Constants:
first_one = 'First one'
second_one = 'Second one'
To get a list of attributes I'd need to make a method that does that.
I'm also considering named tuple but I again don't know how to get the list of values:
class Constants(typing.NamedTuple):
first_one = 'First one'
second_one = 'Second one'
EDIT:
Enum
does not seem to have such option neither and moreover I need to get values this way Constants.first_one.value
EDIT2:
Basically, all I want is to know if there is some collection that behaves like this:
class Properties:
PHONE = 'phone'
FIRSTNAME = 'firstname'
LASTNAME = 'lastname'
@classmethod
@property
def values(cls):
return [x for x in dir(cls) if not x.startswith('__') and x != 'values']
print(Properties.PHONE)
> phone
print(Properties.FIRSTNAME)
> firstname
print(Properties.values)
> ['phone', 'firstname', 'lastname']