In the comments you say:
The input file contains many steps and every time I add a new step I need to configure the type of analysis
If you understand correctly, you say that every time you add a new step, you create a new Enum object. Perhaps that is why you see your “mistake”. The values of two different Enum objects, despite the same name and order, are not necessarily compared as equal. For instance:
import enum Analysis1 = enum.Enum("Analysis", "static dynamic") Analysis2 = enum.Enum("Analysis", "static dynamic")
But:
>>> Analysis1.static == Analysis2.static False
This is because the equality operator is not defined for Enum objects, as far as I can tell, so the default id check behavior is used.
As @martineau notes in the comments, one way to avoid this problem is to use the IntEnum type, which subclasses int and therefore defines the equality operator in terms of the value of Enum , not id :
import enum Analysis1 = enum.IntEnum("Analysis", "static dynamic") Analysis2 = enum.IntEnum("Analysis", "static dynamic")
Then:
>>> Analysis1.static == Analysis2.static True
Why Enum and IntEnum ?
At first glance, it may seem that IntEnum always what we want. So what is the point of Enum ?
Suppose you want to list two sets of items, for example, fruits and colors. Now “orange” is both a fruit and a color. So we write:
Fruits = enum.IntEnum("Fruits", "orange apple lemon") Colors = enum.IntEnum("Colors", "orange red blue")
But now:
>>> Fruits.orange == Colors.orange True
But, philosophically speaking, “orange” (fruit) is not the same as “orange” (color)! Can't we tell them apart? Here, subclasses of int on IntEnum work against us, since both Fruits.orange and Colors.orange set to 1 . Of course, as we saw above, the Enum comparison compares id s, not values. Since Fruits.orange and Colors.orange are unique objects, they are not compared as equal:
Fruits = enum.Enum("Fruits", "orange apple lemon") Colors = enum.Enum("Colors", "orange red blue")
So, to:
>>> Fruits.orange == Colors.orange False
and we no longer live in a world where some colors are things you can find in the products section of your local grocery store.