Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22251
| Date | 2012-03-27 10:53 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Advise of programming one of my first programs |
| References | <CAKhY55OL1qvq+kqbyKT8gEuFOK4BkgYGZkkyUVb84_H9VVEQhA@mail.gmail.com> <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <CAKhY55O9zE_jxF5PvzOF0DGifRT2gZLbRHiuQ_a1vA-aGGDb9g@mail.gmail.com> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1047.1332863574.3037.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Advise of programming one of my first programs Tim Chase <python.list@tim.thechases.com> - 2012-03-27 10:53 -0500
csiph-web