Advise of programming one of my first programs

Tim Chase python.list at
Wed Mar 28 01:32:05 CEST 2012

On 03/27/12 16:53, Anatoli Hristov wrote:
> On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote:
>>> On 03/27/12 10:32, Prasad, Ramit wrote:
>>>> fileread = open('myfile.txt','r')
>>>> tbook = eval(
>>>> fileread.close()
>>> The use of eval is dangerous if you are not *completely* sure what is
>>> being passed in. Try using pickle instead:
>> Or, depending on the use, you might use ast.literal_eval()
> Thanks, but I`m still far from for dose details I thing:)

[reordered to make the commenting inline instead of top-posted]

To make it safer, just change eval( to 
ast.literal_eval( and insert "import ast" at the 
top of your script.


More information about the Python-list mailing list