Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!border1.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed1.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; "'',": 0.07; 'assignment': 0.07; 'subject:code': 0.07; 'suppose': 0.07; 'exec': 0.09; 'mode:': 0.09; "they've": 0.09; 'similarly,': 0.16; 'for?': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'compilation': 0.24; 'compiled': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '>>>>': 0.31; 'option': 0.32; "can't": 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; "you're": 0.61; 'evaluate': 0.72; '2015': 0.84; 'want:': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=JSsuSh75gSONhyZgJRIdly7KqG5BH2LzkSmjwAdBEq0=; b=1GItes+LqcTsJvv7JH0urTzwcXkBTDUfGuIYNC7bpERSUb8I4ye8WkdZ+5PBxKpywC OCOUUVPk0erb1JvR964cmAGL7o76fXvDB9Jaq9ZvUjOAQoaIrjing9s5n8T9dRu3UEf8 aW8hq4iPt7Z3j0lPj4eGdpefwZ9fmX5QD1jGdd37i6yFZjwstXZ3I0KUD2Xc6hIjy647 pLrnN+RofbbfyzJuh5TMYi8eGhCiVGiPKvC3Vz1kEN9rkMICaMmCs+SUvF0CCyPxFkhu HPy8XlcXVgPRCYxN7x6Gu0gRvRlZp1DMftm9QdLXyT20WvQ6K5cbLvEkLf/OI6TXVZer GHdQ== X-Received: by 10.107.136.89 with SMTP id k86mr9998533iod.63.1431315439203; Sun, 10 May 2015 20:37:19 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <66312d54-de5a-4015-99b5-41d332559e00@googlegroups.com> From: Ian Kelly Date: Sun, 10 May 2015 21:36:38 -0600 Subject: Re: code blocks To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431315447 news.xs4all.nl 2835 [2001:888:2000:d::a6]:60488 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90340 On Sun, May 10, 2015 at 9:31 PM, Ian Kelly wrote: > On Sun, May 10, 2015 at 7:39 PM, zipher wrote: >> Similarly, you'd want: >> >>>>> encode(codestr) >> >> to instantiate all objects in the codestr. You can't do this with eval, because it doesn't allow assignment (eval(n=2) returns "InvalidSyntax"). > > Is exec what you're looking for? > >>>> exec('n = 2') >>>> print(n) > 2 I just found that eval can be used to evaluate a code object compiled in the 'exec' mode: >>> eval(compile('n = 42', '', 'exec')) >>> n 42 Interesting. But I suppose that the mode is really just a compilation option and there's not really much distinction as far as eval is concerned once they've been compiled.