fsm - Python graceful fail on int() call? -


I have to create a rudimentary FSM in a class, and write it in Python. For the assignment we need to read the transition to the machine from the text file. For example, an FSM with 3 states, each of which has 2 possible changes, with the possible input 'A' and 'B', a text file is in Volode that looks like this:

  2 # The first line is the list of all final states 0A B1B2A1B2A2B2B1  

I read one more point I am trying to come in a manner that converts line and states into interses at one time, whereas input vals are converted into wires Keeping it in the form Originally this idea is:

  self.finalStates = f.readline (). Strip ("\ n"). In line for the partition (""): current_state, input_val, next_state = ("a \") x {int (x) line.strip ("\ n") for x. Of course, when it tries to int ("a") a valueError I know that I can use a conventional loop and just say eliter I could catch up, but I wanted another phenomenon to do this. 
"post-text" itemprop = "text">

You should actually try to parse those tokens that you expect to be an integer

  f: tokens = Line.split ("") current_state, input_val, next_state = int (token [0]), token [1], int (token [2])  

Essentially more- Readable:

In line for: current_state, input_val, next_state = parcelline (line) dir paraseline (line): token = line split ("") return (int (token [0] ), Token [1], int (token [2]))

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -