How to clear screen in Python interactive shell mode?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • A. L.

    #1

    How to clear screen in Python interactive shell mode?

    In Python interactive mode, is there some function acting like 'clear'
    command in bash? Could somebody here give some advice?

    Thanks in advance.

  • Laszlo Zsolt Nagy

    #2
    Re: How to clear screen in Python interactive shell mode?

    A. L. wrote:
    [color=blue]
    >In Python interactive mode, is there some function acting like 'clear'
    >command in bash? Could somebody here give some advice?
    >
    >[/color]
    Under Linux/UNIX system (on x86 at least) you can use the CTRL+L
    combination to clear the screen.
    I do not now similar for Windows and MACs.

    Les

    Comment

    • A. L.

      #3
      Re: How to clear screen in Python interactive shell mode?

      Thank you very much. I have tested it under Cygwin, and that works. But
      it fails under Windows Python Shell Mode.

      Comment

      • Steven D'Aprano

        #4
        Re: How to clear screen in Python interactive shell mode?

        On Thu, 15 Sep 2005 21:18:33 -0700, A. L. wrote:
        [color=blue]
        > In Python interactive mode, is there some function acting like 'clear'
        > command in bash? Could somebody here give some advice?
        >
        > Thanks in advance.[/color]


        Something like this may help:

        def clearscreen(num lines=100):
        """Clear the console.

        numlines is an optional argument used only as a fall-back.
        """
        import os
        if os.name == "posix":
        # Unix/Linux/MacOS/BSD/etc
        os.system('clea r')
        elif os.name in ("nt", "dos", "ce"):
        # DOS/Windows
        os.system('CLS' )
        else:
        # Fallback for other operating systems.
        print '\n' * numlines


        --
        Steven.

        Comment

        • A. L.

          #5
          Re: How to clear screen in Python interactive shell mode?

          I have tested it under windows python console, and it works.

          Thank you very much.

          Comment

          • bruce

            #6
            Re: How to clear screen in Python interactive shell mode?

            elif os.name in ("nt", "dos", "ce"):
            # emacs/Windows
            What`s the right statement here?

            Comment

            Working...