[Tutor] parsing woes
Alan Gauld
alan.gauld at blueyonder.co.uk
Sun Aug 24 17:55:23 EDT 2003
> > try:
> > if ....
> > except IndexError:
> > pass
> >
> > That will simply ignore the index error.
> This is what I am currently doing. It seems to be working fine.
You were checking each line with try/except. I am suggesting
using just 1 try/exeptr pair to encapsulate all the indexing
operations - saves some code and im[roves readability, at
the cost of losing the precision of the error response.
> > if num > 2: print parameters[2]
> > if num > 3: print "Too many parameters!"
> >
> I'll have to look into the len function. I was under the assumption
that
> not knowing what the length of the parameter would prohibit its use.
Its purpose is to tell you how many things are in the sequence.
> parameters could be a single letter or number of multiple
letter/number
> combination. I only know that they will be space-delimited.
OK but by this time you have already "split" them into a list.
len() will tell you how many items are in the list. It won't
tell you anything about what "the things" are, just how many...
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list