Re: reading raw variables from file
- From: "Francesco Guerrieri" <f.guerrieri@xxxxxxxxx>
- Date: Fri, 30 Nov 2007 12:50:52 +0100
On Nov 30, 2007 5:57 AM, Astan Chee <stanc@xxxxxxxxx> wrote:
Hi,
I have a file that might contain literal python variable statements at
every line. For example the file info.dat looks like this:
users = ["Bob", "Jane"]
status = {1:"ok",2:users[0]}
the problem is I want to read this file and load whatever variables
written in it as normal python variable statements so that when i read
the file, my users var will be ["Bob","Jane"] and my status var will be
{1:"ok",2:users[0]} . Is there an easy way of doing this instead of
parsing the files and checking said types?
A much safer approach would be to use Yaml, which provides safely and
easily the requested feature
Give a look at:
http://pyyaml.org/
bye,
francesco
.
- Prev by Date: Re: Oh no, my code is being published ... help!
- Next by Date: Re: Global variables within classes.
- Previous by thread: Re: reading raw variables from file
- Next by thread: ImportError: No module named sax.handler?
- Index(es):