![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Hobbyist Programmer
Join Date: Dec 2005
Posts: 118
Rep Power: 0
![]() |
Sorry. Maybe it depends on your operating system. It works in WinXP...
|
|
|
|
|
|
#22 |
|
Hobbyist Programmer
|
Never mind. It worked after all. Thanks.
Another question though: Is there a way to remove a number of indefinate size (or, failing that, clear the screen)? |
|
|
|
|
|
#23 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
In the Windows command shell you can use:
import os
os.system("CLS")
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#24 |
|
Hobbyist Programmer
|
Thanks!
|
|
|
|
|
|
#25 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Instead of a for loop:
print '\n' * 25 |
|
|
|
|
|
#26 |
|
Hobbyist Programmer
|
Ooh, quite fancy
|
|
|
|
|
|
#27 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Yeah. If you know how many characters wide your terminal is (you can find this by reading the output of `tput cols` on *nix) you can have you can easily clear the current line and write new text to it. So for example (untested):
import time, sys
# Get the amount of characters wide the terminal is.
# On *nix you can do: int(os.popen("tput cols").read().strip())
width = getTerminalWidth()
message1 = "Message number 1"
# Print message1 to the terminal, padded to the end of the line with spaces.
# If we pad the output then we know how many backspaces characters
# we need to write out to clear the whole line. width - len(message1) will
# give us the amount of space characters we need.
sys.stdout.write(message1 + " " * (width - len(message1)))
# Flush the text we've written to stdout. If Python doesn't see a newline
# it doesn't flush for you.
sys.stdout.flush()
# Pause execution for a second...
time.sleep(1)
# Now clear the line
sys.stdout.write("\b" * width)
# And write a new message
sys.stdout.write("Message number 2...\n") |
|
|
|
|
|
#28 |
|
Hobbyist Programmer
Join Date: Dec 2005
Posts: 118
Rep Power: 0
![]() |
Doesn't '\r' take you to the beginning of the line you're on?
|
|
|
|
|
|
#29 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Yip. Should help you a bit, Cerulean:
sys.stdout.write("\b" * width)
sys.stdout.write("\r") |
|
|
|
|
|
#30 | |
|
Programmer
Join Date: Apr 2005
Posts: 73
Rep Power: 4
![]() |
Quote:
class Evil(object):
def __init__(self, val):
self.val = int(val)
self.state = False
def __add__(self, other):
return Evil(self.val + other)
def __pos__(self):
if self.state:
self.val += 1
self.state = not self.state
return self
def __repr__(self):
return str(self.val)
x = Evil(2)
++x
print x
y = (++x) + 2
++y
print y |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|