<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Ah yes, I see what you mean:</p>
    <p>class Test():<br>
             x = 1<br>
             print (x)                         # Prints 1<br>
             print([x+i for i in range(1,3)])  # NameError (x)</p>
    <p>Anyway, I  apologise for posting to Python-Dev on was a known
      issue, and turned out to be more me asking for help with
      development with Python, rather than development of Python.  (My
      original use case was a scripting language that could contain
      embedded Python code).  Thanks to Nick for his original answer.<br>
    </p>
    <p>Rob Cliffe</p>
    <br>
    <div class="moz-cite-prefix">On 11/06/2018 23:31, Eric Fahlgren
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAP2Qz+UMGGjnG0RTkBWdHxo+m2ddgm5=B1Yu-wW=kcZs+OeXgQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_default" style="color:#000000"><span
            style="color:rgb(34,34,34)">On Mon, Jun 11, 2018 at 3:10 PM
            Rob Cliffe via Python-Dev <<a
              href="mailto:python-dev@python.org" moz-do-not-send="true">python-dev@python.org</a>>
            wrote:</span><br>
        </div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Skip, I
            think you have misunderstood the  point I was making.  It
            was <br>
            not whether the loop variable should leak out of a list
            comprehension.  <br>
            Rather, it was whether a local variable should, so to speak,
            "leak into" <br>
            a list comprehension.  And the answer is: it depends on
            whether the code <br>
            is executed normally, or via exec/eval.  Example:<br>
            <br>
            def Test():<br>
                   x = 1<br>
                   print([x+i for i in range(1,3)])              #
            Prints [2,3]<br>
                   exec('print([x+i for i in range(1,3)])') # Raises
            NameError (x)<br>
            Test()<br>
            <br>
            I (at least at first) found the difference in behaviour
            surprising.<br>
          </blockquote>
          <div><br>
          </div>
          <div class="gmail_default" style="color:rgb(0,0,0)">​Change
            'def' to 'class' and run it again.  You'll be even more
            surprised.​</div>
        </div>
      </div>
      <div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
        <table style="border-top: 1px solid #D3D4DE;">
          <tbody>
            <tr>
              <td style="width: 55px; padding-top: 13px;"><a
href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
                  target="_blank" moz-do-not-send="true"><img
src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png"
                    alt="" style="width: 46px; height: 29px;"
                    moz-do-not-send="true" height="29" width="46"></a></td>
              <td style="width: 470px; padding-top: 12px; color:
                #41424e; font-size: 13px; font-family: Arial, Helvetica,
                sans-serif; line-height: 18px;">Virus-free. <a
href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
                  target="_blank" style="color: #4453ea;"
                  moz-do-not-send="true">www.avg.com</a> </td>
            </tr>
          </tbody>
        </table>
        <a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
          height="1" moz-do-not-send="true"> </a></div>
    </blockquote>
    <br>
  </body>
</html>