I am implementing a transition tables as a class attribute with,
class Phase:
num_states = 15
transition_table = [[False for _ in range(num_states)] for _ in range(num_states)]
but it failed with NameError: name 'num_states' is not defined
.
However, 1d array works as expected,
class Phase:
num_states = 15
transition_table = [False for _ in range(num_states)] # this works
I was wondering why this is the case, as num_states is defined before transition_table and it should have access to the previous one?
New contributor
Hongdan Wang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1