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


Groups > comp.lang.python > #90340

Re: code blocks

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 2015-05-10 21:36 -0600
Subject Re: code blocks
Newsgroups comp.lang.python
Message-ID <mailman.341.1431315447.12865.python-list@python.org> (permalink)

Show all headers | 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