Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'purely': 0.09; 'cc:addr :python-list': 0.15; '-tkc': 0.16; 'eval': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:programming': 0.16; 'passed': 0.20; 'wrote:': 0.21; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'cc:addr:python.org': 0.27; 'code': 0.29; 'to:2**1': 0.30; 'cc:2**0': 0.31; 'in.': 0.33; 'url:python': 0.34; 'should': 0.35; 'sure': 0.36; 'url:org': 0.36; 'received:70': 0.38; 'being': 0.39; 'simply': 0.65; 'url:5': 0.67; 'glance': 0.84; 'received:50.22': 0.84; 'suggests': 0.84; 'url:release': 0.84 Date: Tue, 27 Mar 2012 10:53:11 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: "Prasad, Ramit" Subject: Re: Advise of programming one of my first programs References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332863574 news.xs4all.nl 6882 [2001:888:2000:d::a6]:45147 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22251 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