1

In my .zshrc i have the alias alias cls='printf "\033[H\033[3J"'. With this I can run os.system(cls) in my Python script to clear the screen (and clear buffer, totally clean, just prompt and no scrollback.)

This works on Big Sur but now I'm on Sequoia. Why did it stop working? Running directly os.system('printf "\033[H\033[3J"') doesn't help, nor the old printf "\033c". What's up? (I'm on Python version 3.13.7)

4
  • Running printf "\033c" in Bash still cleares the Terminal window for me with Sequoia. Commented Oct 14 at 13:24
  • yes for me too, but not when run in python script with os.system() nor subprocess.Popen() Commented Oct 14 at 16:08
  • Why not just clear? Commented Oct 14 at 19:05
  • @linc davis - because i don't want the scrollback. has to be clean. Commented Oct 24 at 6:53

2 Answers 2

3

I use alias cls='tput clear' for the shell rather than depending on sending arbitrary control codes to the terminal.

In python, you would just use os.system('tput clear').

4
  • gonna try this! tnx. if it works i'll mark it as the solution Commented Oct 18 at 20:50
  • it didn't, unfortunately Commented Oct 24 at 6:59
  • If the printf works, so should this, unless $TERM is not being set. Commented Oct 24 at 14:14
  • it doesn't clear the scrollback Commented Oct 31 at 11:57
1
print('\033c\033[H\033[3J', end=None)

works. clears buffer, totally clean, just prompt and no scrollback.

2
  • 1
    Try "\033[H\033[2J\033[3J". Note that <ESC>[2J is "erase entire screen" and <ESC>[2J is "erase saved lines". Commented Oct 24 at 8:55
  • 1
    <ESC>[2J erases the screen; <ESC>[3J erases saved lines; and <ESC>[H moves the cursor to the top-left.  <ESC>c does all those, and also resets tabstops etc. too. Commented Oct 24 at 11:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.