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


Groups > comp.lang.python > #104390

Re: exec "x = 3; print x" in a - How does it work?

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: exec "x = 3; print x" in a - How does it work?
Date 2016-03-09 17:34 +1100
Message-ID <mailman.69.1457505285.15725.python-list@python.org> (permalink)
References <nboc29$up4$1@dont-email.me> <56dfba89$0$2805$c3e8da3$76491128@news.astraweb.com> <nboffi$6mo$2@dont-email.me>

Show all headers | View raw


On Wed, Mar 9, 2016 at 5:25 PM, Veek. M <vek.m1234@gmail.com> wrote:
> ah, okay - i'm familiar with the py3 syntax where you do:
> eval('whatever stmt', globals={}, locals={})
> I suppose this: exec " " in NS; syntax is strictly py2?
>
> Many thanks :)

Yeah, that's one of the things that was cleaned up in Py3. Several
pieces of magic syntax were replaced with perfectly ordinary
functions. While there are plenty of people who complain about having
to put parentheses around their print calls, I'm firmly of the opinion
that print(..., file=somefile) is WAY better than the >> syntax that
Py2 used. I can never remember whether it has to go first or has to go
last, and whether it's >> or >>>, etc, etc. It's magic syntax. Py3?
It's a keyword argument. Easy!

ChrisA

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


Thread

exec "x = 3; print x" in a - How does it work? "Veek. M" <vek.m1234@gmail.com> - 2016-03-09 10:57 +0530
  Re: exec "x = 3; print x" in a - How does it work? Ben Finney <ben+python@benfinney.id.au> - 2016-03-09 16:50 +1100
    Re: exec "x = 3; print x" in a - How does it work? "Veek. M" <vek.m1234@gmail.com> - 2016-03-09 11:51 +0530
  Re: exec "x = 3; print x" in a - How does it work? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-09 16:54 +1100
    Re: exec "x = 3; print x" in a - How does it work? "Veek. M" <vek.m1234@gmail.com> - 2016-03-09 11:55 +0530
      Re: exec "x = 3; print x" in a - How does it work? Chris Angelico <rosuav@gmail.com> - 2016-03-09 17:34 +1100

csiph-web