Extracting values from text file

Preben Randhol randhol at bacchus.pvv.ntnu.no
Fri Jun 16 04:36:32 EDT 2006


A short newbie question. I would like to extract some values from a
given text file directly into python variables. Can this be done simply
by either standard library or other libraries? Some pointers where to
get started would be much appreciated.

An example text file:
Some text that can span some lines.

  Apples 34
  56 Ducks

Some more text.

  0.5 g butter

What I first though was if there was possible to make a filter such as:

  Apples (apples)
  (ducks) Ducks
  (butter) g butter

The data can be put in a hash table.

Or maybe there are better ways? I generally want something that is
flexible so one can easily make a filter settings if the text file
format changes.

Thanks in advance

More information about the Python-list mailing list