I am working on a parser and my input file is a description about bunch of things written line by line. So for instance, consider the following two lines and what the corresponding variables in python should look like.
example Line1: position = 1, 1, rotation = 90, 0, 0, mass = 120; Here I want the variables to be position = [1,1,0], rotation = [90,0,0], mass = 
example Line2: position = 1, 1, 2, mass = 120, rotation = 90, 0; Here I want the variables to be position = [1,1,2], rotation = [90,0,0], mass = 
example Line3: mass = 120, rotation = 90, 0; Here I want the variables to be position = [0,0,0], rotation = [90,0,0], mass = 
I know the maximum number of arguments possible for each variable. For example, in the first line above, only two numbers for position ares specified; that means that the third entry in position list is zero. So I need to handle these cases while reading in the file as well. Additionally, the text might not always be in the same order; like shown in the second line above. And finally, sometimes numbers for one variable might not exist at all; like shown in line 3. Here, the position is then read as position = [0,0,0].
How do I implement such stuff? Is there some smart way of doing this? All I have in mind is this: read a line as comma or a space delimited list of words variable and then some how use if else + len(list) to figure out whats going on. But that seems way too tedious and I feel that there might be an easier way to read such things.
Any help is highly appreciated.
Last edited by micseydel
on Thu Jul 11, 2013 2:23 am, edited 2 times in total.
Reason: Locked post.