1,105,320 Community Members

Changing the displayed text while removing it

Member Avatar
inuasha
Light Poster
26 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Alright so I was not sure exactly how to say this, but here is the idea. I have a graph or table I guess you could call that looks like this.

print '''
-----------------------------
|
|
|
|x
|
|
|
|-----------------------------
'''

Then I want to make a change to where x is for example moving it down twice.
How would I go about this without having the first table appear?

Member Avatar
pyTony
pyMod
6,103 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

without having the first table appear?

I do not get it.

Member Avatar
inuasha
Light Poster
26 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I do not get it.

Okay so a simpler example. you do print "hi" then when the script is ran the terminal output hi how do I print hi then like 5 seconds later print "Hello" without the first print statement's output being shown in the terminal.

Member Avatar
pyTony
pyMod
6,103 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

Something like this:

from __future__ import print_function
import sys
import time

print('Hi!', end='')
time.sleep(5)
print(3*'\b'+'Hello!')
sys.stdout.flush()
Member Avatar
nosehat
Newbie Poster
15 posts since Dec 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Depending on your operating system, there are a couple of ways.

Start with

import os

in your script.

If you are on Linux (also Mac I think) you can do:

os.system("clear")

to clear the terminal screen.

If you are on Windows you can do:

os.system("cls")

Note that these probably won't work on IDLE or similar, but will work from the terminal. Clear the screen, and redraw your chart.

Member Avatar
inuasha
Light Poster
26 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks very much pyTony that is not something I even knew existed. Where did you learn python from?

Member Avatar
inuasha
Light Poster
26 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks to you as well nosehat you commented as I posted my last one. Where did you learn this?

Question Answered as of 2 Years Ago by pyTony and nosehat
Member Avatar
pyTony
pyMod
6,103 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

Thanks very much pyTony that is not something I even knew existed. Where did you learn python from?

I learned it basically from online tutorials, but real learning happens when you "play with the language". I do know several languages before starting with TI-58C programmable calculator, where the language is basically key codes as numbers and floating point values, basically assembly level language, 1981 as school boy of 8th grade.

Member Avatar
Gribouillis
Posting Maven
3,452 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 883 [?]
Skill Endorsements: 18 [?]
Moderator
 
0
 

To clear the screen in a linux terminal, use this

print("\x1B[2J")
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: