LParser - A Python literal expression parser

Overview

This extension module parses Python literals from a file. An intended use is for human readable data storage (configuration files, data files, etc.). It is copyrighted under a Python style license.

The format of the input is the same as Python (with some extensions). Lists, tuples, dictionaries, floats, integers, strings, and comments are recognized. Triple quoted strings are not recognized. Long integers and complex numbers are not recognized. Numbers are returned as integers if possible. All sequences are returned as lists.

The extensions to the syntax are:

An example data file using these extensions looks like this:

    option1 = 10
    option2 = (1 2 3)

    # some useful commentary
    subsystem1 = {
    option1 = 10.102 # a little comment
    option2 = "This is a quoted string"
    good_option = on
    }
when parsed the following dictionary is returned:
    {'option1': 10, 'subsystem1': {'option1': 10.102, 'good_option': 'on',
     'option2': 'This is a quoted string'}, 'option2': [1, 2, 3]}

On a parse error, an LParserError exception is raised. The value of the exception gives the line number and a short description of what when wrong.

Features

Known Bugs

Download

Latest version can be downloaded from my python directory.


Updated: Sun, 09 Apr 2000 15:14:14 -0600
Neil Schemenauer <nas@arctrix.com>