Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22251 > unrolled thread

Re: Advise of programming one of my first programs

Started byTim Chase <python.list@tim.thechases.com>
First post2012-03-27 10:53 -0500
Last post2012-03-27 10:53 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Advise of programming one of my first programs Tim Chase <python.list@tim.thechases.com> - 2012-03-27 10:53 -0500

#22251 — Re: Advise of programming one of my first programs

FromTim Chase <python.list@tim.thechases.com>
Date2012-03-27 10:53 -0500
SubjectRe: Advise of programming one of my first programs
Message-ID<mailman.1047.1332863574.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web