<div dir="ltr"><div>Hello,</div><div><br></div><div>I don't see why creating a clear command would interfere with dict.clear() which is a function/method.</div><div><br></div><div>Although my first idea was a clear command, I have no problem if it is a clear() function from site.py.</div><div><br></div><div>I didn't suggest cls because it is normally used to mean class.</div><div><br></div><div>I use Windows and tested a simple (possibly not the best of course) solution that seems to work in REPL (but not in IDLE).</div><div><br></div><div>import os</div><div>import sys</div><div><br></div><div>def clear():</div><div> if sys.platform == 'win32':<br> os.system('cls')<br> else:<br> os.system('clear')<br></div><div><br></div><div><br></div><div>Best regards,</div><div><br></div><div>JM</div><div><br><br>segunda-feira, 19 de Setembro de 2016 às 03:33:45 UTC+1, Steven D'Aprano escreveu:</div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">On Sat, Sep 17, 2016 at 11:51:16AM +0100, João Matos wrote:
<br>> Hello,
<br>>
<br>> I would like to suggest adding a clear command (not function) to Python.
<br>
<br>While technically "clear" could be a command, I think it should not be.
<br>
<br>First off, making clear a reserved keyword, and a statement, like print
<br>in Python 2, raise or import, would be a major backwards compatibility
<br>break. It would mean dict.clear() has to be renamed, and it would break
<br>lots of existing code.
<br>
<br>So making clear a keyword is not going to happen.
<br>
<br>If could be a pseudo-built-in, like help(), quit() and exit(), added to
<br>built-ins by the site module. In that case, it is *technically* possible
<br>to have it operate without the parentheses:
<br>
<br>class ClearType:
<br> def __repr__(self):
<br> # code to clear the screen here
<br> ...
<br>
<br>clear = ClearType()
<br>
<br>so that when you enter clear at the interactive interpreter, __repr__ is
<br>called and it clears the screen. But I would argue against it. Instead,
<br>it is better to use the same convention that executable code that has
<br>side-effects should be implemented as a function call.
<br>
<br>So I suggest following the design of exit() and quit():
<br>
<br>py> exit
<br>Use exit() or Ctrl-D (i.e. EOF) to exit
<br>
<br>
<br>class ClearType:
<br> def __repr__(self):
<br> return "Use clear() or Ctrl-L (i.e. FF) to clear the screen"
<br> def __call__(self):
<br> # clear screen code goes here
<br>
<br>clear = ClearType() # or possibly cls ?
<br>
<br>
<br>
<br>That is, *if* we add this function at all.
<br>
<br>Personally, I agree with you. There are many different ways of clearing
<br>the screen, but they depend on the specific terminal used, whether
<br>readline is active or not, the operating system, etc. I think that
<br>interactive use is important enough that we should have a standard way
<br>of clearing the screen. I personally often find myself just holding down
<br>the Enter key until I have a blank screen.
<br>
<br>In this ticket:
<br>
<br><a onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fbugs.python.org%2Fissue27771\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEhqdHPiZhZSc2fYfiwGSG7yf7-Cw';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fbugs.python.org%2Fissue27771\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEhqdHPiZhZSc2fYfiwGSG7yf7-Cw';return true;" href="http://bugs.python.org/issue27771" target="_blank" rel="nofollow">http://bugs.python.org/<wbr>issue27771</a>
<br>
<br>Raymond Hettinger mentions that it is an often-requested feature by
<br>learners, and I believe that IDLE has an active task for this feature:
<br>
<br><a onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fbugs.python.org%2Fissue6143\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVMzXFh62iiStxPojp1QsJYeG2Rg';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fbugs.python.org%2Fissue6143\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFVMzXFh62iiStxPojp1QsJYeG2Rg';return true;" href="http://bugs.python.org/issue6143" target="_blank" rel="nofollow">http://bugs.python.org/<wbr>issue6143</a>
<br>
<br>but I don't see any tasks for a clear screen command for the default
<br>REPL.
<br>
<br>I'm in favour of adding a clear() *function* to the site.py module,
<br>similar to exit/quit/help, but not making it "magical" or a keyword that
<br>doesn't require brackets. But I don't know how to implement it for the
<br>large variety of terminals and operating systems supported by Python.
<br>
<br>(The fallback if all else fails is easy: get the height of the terminal,
<br>in lines, and print that many blank lines.)
<br>
<br>
<br>--
<br>Steve
<br>______________________________<wbr>_________________
<br>Python-ideas mailing list
<br><a onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="4nBQMRKNAgAJ">Python...@python.org</a>
<br><a onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a>
<br>Code of Conduct: <a onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow">http://python.org/psf/<wbr>codeofconduct/</a>
<br></blockquote></div>