Parsing strings from files.

Gerrit Holl gerrit.holl at pobox.com
Mon Dec 13 16:23:49 EST 1999


Hello,

consider the following file:

### cut here ###
foo="this is an easy-to-parse string"
bar='''this string, containing ", ' and newlines like


this, is a little harder to parse'''
foobar='this "\'string\'" is \'\'\'hard'+' '+'to parse'
### cut here ###

I want to parse the string literals from a file, so I want to get a dict like
this:
{
'foo': 'this is an easy-to-parse string',
'bar': 'this string, containing ", \' and newlines like\n\n\nthis, is a little harder to parse',
'foobar': 'this "\'string\'" is \'\'\'hard to parse'
}

I want this because I've got a user configuration file, and because some
strings are very long and contain newlines, I don't want to be the
file newline delimited. I want to have the same string rules as Python has;
so the code exists. I just want to reuse it. But how?

regards,
Gerrit.

-- 
Writing unreadable Python code is easy:
>>> exec 'exec \'print \\\'\\\\\\\\\\\'\''
\




More information about the Python-list mailing list