Describe what did you try to do with TM1py
What is the right way to compare the element_type property?
I tried the following to check if it is a consolidated element. But did not work.
Can it recognize the string above rather than the enum type?
Version
@fidong
It is a good practice to provide some code to replicate what you are trying to do. Anyway, since you are talking about element_type, the below part should help you solve that.
from TM1py.Services import TM1Service
with TM1Service(address=ADDRESS, port=PORT, ssl=SSL, user=USER, password=PASSWORD) as tm1:
element_type_dict = tm1.elements.get_element_types(dimension_name='Period', hierarchy_name='Period')
# filter the dict with the required element name to find its element_type
if element_type_dict['01'] == 'Consolidated':
print("A Consolidated element")
# filter the dict with the required element name to find its element_type
if element_type_dict['01'] == 'Numeric':
print("A Numeric element")
# loop through the dict and print all element names & types
for element, _type in element_type_dict.items():
print(f'"{element}" is a {_type} element')
@fidong,
in case you are dealing with the Element object, you can just explicitly convert the enum type into a str before you do the comparison.
from TM1py.Services import TM1Service
with TM1Service(address="localhost", port=12354, ssl=True, user="admin", password="apple") as tm1:
hierarchy = tm1.hierarchies.get(dimension_name="Product", hierarchy_name="Product")
element = hierarchy.get_element("483")
if str(element.element_type) == "Numeric":
print(element.name)
Thanks all yes that explains what I should do.