<div class="gmail_quote">On Sat, Sep 24, 2011 at 11:27 AM, Georg Brandl <span dir="ltr">&lt;<a href="mailto:g.brandl@gmx.net">g.brandl@gmx.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Am <a href="tel:24.09.2011%2001" value="+12409201101">24.09.2011 01</a>:32, schrieb Guido van Rossum:<br>
<div class="im">&gt; On Fri, Sep 23, 2011 at 4:25 PM, anatoly techtonik &lt;<a href="mailto:techtonik@gmail.com">techtonik@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Currently if you work in console and define a function and then<br>
&gt;&gt; immediately call it - it will fail with SyntaxError.<br>
&gt;&gt; For example, copy paste this completely valid Python script into console:<br>
&gt;&gt;<br>
&gt;&gt; def some():<br>
&gt;&gt;  print &quot;XXX&quot;<br>
&gt;&gt; some()<br>
&gt;&gt;<br>
&gt;&gt; There is an issue for that that was just closed by Eric. However, I&#39;d<br>
&gt;&gt; like to know if there are people here that agree that if you paste a<br>
&gt;&gt; valid Python script into console - it should work without changes.<br>
&gt;<br>
&gt; You can&#39;t fix this without completely changing the way the interactive<br>
&gt; console treats blank lines. None that it&#39;s not just that a blank line<br>
&gt; is required after a function definition -- you also *can&#39;t* have a<br>
&gt; blank line *inside* a function definition.<br>
<br>
</div>While the former could be changed (I think), the latter certainly cannot.<br>
So it&#39;s probably not worth changing established behavior.</blockquote><div><br></div>I&#39;ve just hit this UX bug once more, but now I more prepared. Despite</div><div class="gmail_quote">Guido&#39;s proposal to move into python-ideas, I continue discussion here,</div>

<div class="gmail_quote">because:</div><div class="gmail_quote"><br></div><div class="gmail_quote">1. It is not a proposal, but a defect (well, you may argue, but please, don&#39;t)</div><div class="gmail_quote">2. This thread has a history of analysis of what&#39;s going wrong in console</div>

<div class="gmail_quote">3. This thread also has developer&#39;s decision that answers the question</div><div class="gmail_quote">    &quot;why it&#39;s so wrong?&quot; and &quot;why it can&#39;t/won&#39;t be fixed&quot;</div>

<div class="gmail_quote">4. Yesterday I&#39;ve heard from a Java person that Python is hard to pick up</div><div class="gmail_quote">    and remembered how I struggled with indentation myself trying to</div><div class="gmail_quote">

    &#39;learn by example&#39; in console</div><div class="gmail_quote"><br></div><div class="gmail_quote">Right now I am trying to cope with point (3.). To summarize, let&#39;s speak code</div><div class="gmail_quote">that is copy/pasted into console. Two things that will make me happy if they</div>

<div class="gmail_quote">behave consistently in console from .py file:</div><div class="gmail_quote"><br></div><div class="gmail_quote">---ex1---</div><div class="gmail_quote">def some():<br>    print &quot;XXX&quot;<br>
some()<br>
</div><div class="gmail_quote">---/ex1---</div><div class="gmail_quote"><br></div><div class="gmail_quote">--ex1.output--</div><div class="gmail_quote">[ex1.py]</div><div class="gmail_quote"><div class="gmail_quote">XXX</div>

<div>[console]</div><div><div>  File &quot;&lt;stdin&gt;&quot;, line 3</div><div>    some()</div><div>       ^</div><div>SyntaxError: invalid syntax</div></div><div>--/ex1.output--</div></div><div class="gmail_quote"><br>

</div><div class="gmail_quote"><br></div><div class="gmail_quote">--ex2--</div><div class="gmail_quote">def some():</div><div class="gmail_quote">pass</div><div class="gmail_quote">--/ex2--</div><div class="gmail_quote">
<br>
</div><div class="gmail_quote"><div class="gmail_quote">--ex2.output--</div><div class="gmail_quote">[ex2.py]</div><div class="gmail_quote"><div class="gmail_quote">  File &quot;./ex2.py&quot;, line 2</div><div class="gmail_quote">

    pass</div><div class="gmail_quote">       ^</div><div class="gmail_quote">IndentationError: expected an indented block</div><div>[console]</div></div><div class="gmail_quote"><div class="gmail_quote">  File &quot;&lt;stdin&gt;&quot;, line 2</div>

<div class="gmail_quote">    pass</div><div class="gmail_quote">       ^</div><div class="gmail_quote">IndentationError: expected an indented block</div><div>--/ex2.output--</div></div><div><br></div></div><div class="gmail_quote">

<br></div><div class="gmail_quote">The second example already works as expected. Why it is not possible to fix ex1? Guido said:</div><div class="gmail_quote"><br></div><div class="gmail_quote">&gt; You can&#39;t fix this without completely changing the way the interactive</div>

&gt; console treats blank lines.<div><br></div><div>But the fix doesn&#39;t require changing the way interactive console treats blank lines at all. It only requires to finish current block when a dedented line is encountered and not throwing obviously confusing SyntaxError. At the very least it should not say it is SyntaxError, because the code is pretty valid Python code. If it appears to be invalid &quot;Python Console code&quot; - the error message should say that explicitly. That would be a correct user-friendly fix for this UX issue, but I&#39;d still like the behavior to be fixed - i.e. &quot;allow dedented lines end current block in console without SyntaxError&quot;. Right now I don&#39;t see the reasons why it is not possible.</div>

<div><br></div><div>Please speak code when replying about use cases/examples that will be broken - I didn&#39;t quite get the problem with &quot;global scope if&quot; statements.<br><div class="gmail_quote">-- <br>anatoly t. </div>

</div>