[Tutor] files - strings - lists

Chris or Leslie Smith smiles at worksmail.net
Wed Nov 23 18:19:50 CET 2005


| 
| With these tools the solution is pretty simple. 

I agree that handling this with Python is pretty straightforward, but I'm wondering if there exists some sort of mechanism for reading these types of well structured (though not XML format, etc...) files. Something like a reverse template, somewhat like the templates that are used to interpret dates and such in the time module (strftime, is it?).  Something like this, where you put a command on each line telling what (if anything) to do:

templ = '''
<line>1 Polonijna Liga Mistrzow    #no command other than signifying a line is to be read
<line>26 wrzesnia 2005
<line:split:a=2,b=3> 6 12 6 4 1    #here we need to do a split and keep 2 and 3, assigning them to a and b
<line> 0 1 0
<rpt<line:split:c=0,d=2>Bohossian - Kolinski    #c and d would have to be a list since there is a rpt command
<line>1 
<linex4:split:e=2>      1.000 9 13 19    #the x4 says to do this command 4 times
      2.000 2 4 16
      1.000 10 8 17
      0.000 8 6 17
/rpt>

I know you could write an regex to handle it, but I'm wondering if there is a kinder method around.

Wondering,
/c


More information about the Tutor mailing list