I am building a program that will eventually be able to construct finite automata and am in the early stages of reading in the txt file to set up my variables (states, alphabet, starting position, final positions, and rules, respectively). Here is the code I have thus far:
def read_dfa(dfa_filename):
dfa = open(dfa_filename, 'r')
count = 0
for line in dfa:
count += 1
states, alphabet, initial, final, rules = (line.format(count, line.strip()))
The issue I am currently facing is that lines 1:4 will always provide the data I need, however, the rules variable could be just line 5, or it could be multiple lines (5:n). How do I make it so I can successfully store the lines I want to each appropriate variable? This is the error I am faced with: 'ValueError: Too many values to unpack (expected 5)' This is an example of what dfa_filename could be:
q1,q2 #states
a,b #alphabet
q1 #initial
q2 #final
q1,a,q2 #rules
q1,b,q1 #rules
q2,a,q2 #rules
q2,b,q2 #rules