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?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: exec "x = 3; print x" in a - How does it work?
Date Wed, 9 Mar 2016 17:34:42 +1100
Lines 17
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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de oGalitlYlSTj/BIzozoVsQ9e/YGT2seZgQ7uJWk0E8qg==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'used.': 0.05; 'plenty': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'cleaned': 0.09; 'okay': 0.09; 'yeah,': 0.09; 'syntax': 0.13; 'wed,': 0.15; '2016': 0.16; 'ah,': 0.16; 'argument.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic': 0.16; 'parentheses': 0.16; 'py3': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'exec': 0.22; 'suppose': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'pieces': 0.27; 'complain': 0.29; "i'm": 0.30; 'print': 0.30; 'received:google.com': 0.35; 'functions.': 0.35; 'replaced': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'keyword': 0.36; 'subject:" ': 0.36; 'subject:work': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'things': 0.38; 'received:209': 0.38; 'several': 0.38; 'where': 0.40; 'strictly': 0.64; 'mar': 0.65; 'calls,': 0.84; 'chrisa': 0.84; 'easy!': 0.84; 'etc,': 0.84; 'to:none': 0.91; 'do:': 0.91; 'subject:; ': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=uCPwxEI/gkWeOQnVpm2F/NkdBQq129uBuYDz6+V5Z2k=; b=HY2Q4FgxF6xTAYCPEPysAO+2JmeyvPMEyUMxQtGTrV840eBpJFriBFHIuLUJ/Spz9w aGplyiCYd8gVahhW49lIil6MFG5ognT0kWO4C0fcvLtnK5ZhGN4SNpc+Sy5rVfko23jr HE+TFfADN5JLI34NB9BTy1YVKCi/A+Gg6deoI387PAecuwmeVqVYN44gu/nRkpp/RRRC GdxfGqobuWOI4Lz751IDhjumACEpuXQki1Lzt0159YrASZEWhkjBtwPHbnvExZ39PP9J O3mkz4BpWAPxsplU+EZlyTWRGIp7zxwv0M8pnrhtapx6az8AJKNb0sWtXNocXpK6gpKK d3SA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=uCPwxEI/gkWeOQnVpm2F/NkdBQq129uBuYDz6+V5Z2k=; b=Rp5LTVP3PEzyKUi174ALYCwRX/PMP1Y6l7IHibgghOkzSs2ANNgk7XuYNnerdLuaJv G9Q5zMWdkMRWcyq9zz8JR7Bzh5qdFZe8CqbdjkTdpeQyDYek1N2AnTLfR35G8+OmLWg/ oU8R9m3f6/dCewMAgIEoOHXQnG4HfkH0RVBq25+nuxoRtE3K6yVmZfUKu+ACHdrZTdG6 S4VSg4TlQRICcPdT4vyce9MOuACuqNyppazuCw6K/5ZaEb9EcBd/XWlPb0jMg0McddrP UjekrosY3fvY4wjTv+fHq7eckx+sjloObPFfqgczdmdGOEDih0Sp0zFF8Dpm3OqrL2GJ C00g==
X-Gm-Message-State AD7BkJIkeZPoRBZ0g4T/vH2NnOn4BzxCapjFJNGvhugwdSyR84wAprwwSPHmwrVR+xvqabjVWpyM1PvjU7/fyA==
X-Received by 10.107.47.163 with SMTP id v35mr28991531iov.19.1457505282936; Tue, 08 Mar 2016 22:34:42 -0800 (PST)
In-Reply-To <nboffi$6mo$2@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
Xref csiph.com comp.lang.python:104390

Show key headers only | 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