Re: reading raw variables from file
- From: Bruno Desthuilliers <bruno.42.desthuilliers@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Nov 2007 12:27:54 +0100
Martin Blume a écrit :
"Astan Chee" schriebI 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?
You might want to look at the eval, exec and execfile;
Or just import...
but bear in in mind Paddy's warning about security.
+10
.
- Follow-Ups:
- Re: reading raw variables from file
- From: Martin Blume
- Re: reading raw variables from file
- References:
- reading raw variables from file
- From: Astan Chee
- Re: reading raw variables from file
- From: Martin Blume
- reading raw variables from file
- Prev by Date: Re: Witch editor to use!
- Next by Date: Re: Oh no, my code is being published ... help!
- Previous by thread: Re: reading raw variables from file
- Next by thread: Re: reading raw variables from file
- Index(es):
Relevant Pages
|