formatted input

Diez B. Roggisch deets at web.de
Tue Sep 7 18:03:21 EDT 2010


Bob <roberto.pagliari at gmail.com> writes:

> Hi All,
> I have another question about formatted input. Suppose I am reading a
> text file, and that I want it to be something like this
>
> word11 = num11, word12 = num12, word13 = num13 etc...
> word21 = num21, word22 = num12, word23 = num23 etc...
> etc...
>
> where wordx1 belongs to a certain dictionary of words, say dic1, while
> wordx2 belongs to dic2, the numbers within some range and so on. I was
> wondering if there is something in the standard library I may use to
> check whether the file I am reading has a correct syntax according to
> my rules/dictionaries instead of implementing my own routine that
> would look like
> (pseudocode)
> for each line
>   put words into a list
>   check condition for each word


No, there is no such thing. Either write something from scratch using
string methods, or use pyparsing which is certainly up to the task (and
much more)

Diez



More information about the Python-list mailing list