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:
http://docs.python.org/release/2.5.2/lib/pickle-example.html

Or, depending on the use, you might use ast.literal_eval()

A cursory glance at the OP's code suggests that this may simply be a dict of values-to-lists of purely literals, so literal_eval() should do the job.

-tkc


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

Reply via email to