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.read())
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(fileread.read()) to ast.literal_eval(fileread.read()) and insert "import ast" at the top of your script.

-tkc



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to