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


Groups > comp.lang.python > #90340

Re: code blocks

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 <ian.g.kelly@gmail.com>
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 <CALwzidmXZmK8V=B7jPQaqBvRLOhvGEj1-ZnWcLvngjzh5KuWjQ@mail.gmail.com>
References <mailman.49.1430633046.12865.python-list@python.org> <66312d54-de5a-4015-99b5-41d332559e00@googlegroups.com> <CALwzidmXZmK8V=B7jPQaqBvRLOhvGEj1-ZnWcLvngjzh5KuWjQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sun, 10 May 2015 21:36:38 -0600
Subject Re: code blocks
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.341.1431315447.12865.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sun, May 10, 2015 at 9:31 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Sun, May 10, 2015 at 7:39 PM, zipher <dreamingforward@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

code blocks "Dr. John Q. Hacker" <zondervanz@gmail.com> - 2015-05-02 13:30 -0500
  Re: code blocks Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-03 11:56 +0100
  Re: code blocks zipher <dreamingforward@gmail.com> - 2015-05-10 18:39 -0700
    Re: code blocks Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-10 21:31 -0600
      Re: code blocks Rustom Mody <rustompmody@gmail.com> - 2015-05-10 20:40 -0700
      Re: code blocks zipher <dreamingforward@gmail.com> - 2015-05-11 08:22 -0700
        Re: code blocks zipher <dreamingforward@gmail.com> - 2015-05-11 08:23 -0700
        Re: code blocks Chris Angelico <rosuav@gmail.com> - 2015-05-12 01:40 +1000
        Re: code blocks Peter Otten <__peter__@web.de> - 2015-05-11 18:01 +0200
        Re: code blocks Chris Angelico <rosuav@gmail.com> - 2015-05-12 02:07 +1000
          Re: code blocks zipher <dreamingforward@gmail.com> - 2015-05-11 09:51 -0700
        Re: code blocks Peter Otten <__peter__@web.de> - 2015-05-11 18:59 +0200
    Re: code blocks Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-10 21:36 -0600

csiph-web