| | |
Rewriting output on the same line?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 162
Reputation:
Solved Threads: 1
Is it possible to keep writing the output of a program on the same line instead of moving to a new line every time? The output should be written over the preceding output. An example would be a kind of counter...
say a number that counts from 1 to 10 ...
The normal output of a while loop would be
1
2
3
4
5
etc..
What I want is something that will display 1.. erase it and then display 2.. erase that and display 3 and so on..
say a number that counts from 1 to 10 ...
The normal output of a while loop would be
1
2
3
4
5
etc..
What I want is something that will display 1.. erase it and then display 2.. erase that and display 3 and so on..
"The man who smiles when something goes wrong has thought of someone else to blame"; One of my friends said this on facebook.
0
#2 Nov 9th, 2009
•
•
•
•
Is it possible to keep writing the output of a program on the same line instead of moving to a new line every time? The output should be written over the preceding output. An example would be a kind of counter...
say a number that counts from 1 to 10 ...
The normal output of a while loop would be
1
2
3
4
5
etc..
What I want is something that will display 1.. erase it and then display 2.. erase that and display 3 and so on..
os.system('cls') on Windows or os.system('clear') on Linux.But if you're looking for single character control you'll need to look into curses, which isn't readily available for Windows.
To print on the same line you can end your print statement with a ',' so that instead of printing a new line it prints a space... But that won't help you to clear the previous value
•
•
Join Date: Oct 2009
Posts: 92
Reputation:
Solved Threads: 8
0
#3 Nov 9th, 2009
You might be looking for something like this:
Python Syntax (Toggle Plain Text)
import sys intLoop=0 while intLoop < 100000: sys.stdout.write("%07d\b\b\b\b\b\b\b" % intLoop) intLoop += 1
0
#8 Nov 10th, 2009
You'll either have to follow jlm699's advice or there's no other go, UNLESS.... unless you make a GUI for your program where this is possible...
![]() |
Similar Threads
- Find Text String and Output Line Numbers Text Falls on (VB.NET)
- Replace txt line (Visual Basic 4 / 5 / 6)
- arrays and output (C++)
- Help with the Output line of code (C++)
- control output (C++)
- grep into one line (Perl)
- Interpreting a script line by line (Shell Scripting)
- ostream - how to insert a line of text (C)
- How to read end of line? (C++)
Other Threads in the Python Forum
- Previous Thread: Where's PY2EXE?
- Next Thread: How to use MD5 in Python?
Views: 578 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt apache approximation argv beginner binary book calculator change cipher clear client code compile converter countpasswordentry cturtle dictionaries dictionary drive dynamic examples excel file float format ftp function gui homework import inches input java keyboard library line linux list lists loop maze mouse mysqldb newb number numbers output parsing path plugin port prime program programming projects py2exe pygame pymailer pyqt python random recursion recursive remote script scrolledtext search session signal singleton socket ssh string strings strip table terminal text textarea thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable verify vigenere windows wordgame wxpython xlwt






