Blinky Program

Ryan Spencer jeder at earthlink.net
Fri Nov 28 03:51:53 EST 2003


Hello again Everyone,

	I spent a small amount of time recently writing a program that "blinks"
text. I did it by first having a user input a string,
sys.stdout.write-ing the string, then backing up judging by the number of
characters the string has, re-stdout's over it with blank spaces (judged
again by it's character count), and then backs up again in a never ending
while loop. It keeps each blink .5 seconds spaced as well, and all in the
same position.

Here is the code.

[start code]

#blinky.py
#Make a blinking user inputed (strings) character by using self made "blinky"
#function.

strings = raw_input("Please enter something to blink: ")

#blinky(string_argument, time_pause)
def blinky(strings1, pause):

	import string,time,sys

	string_length = len(strings1)

	replacement = string.replace(strings1,strings1," ")
	
	float(pause)
	
	while 1:
		sys.stdout.write(strings1)
		sys.stdout.flush()
		time.sleep(pause)
		
		sys.stdout.write("\b"*string_length)
		
		sys.stdout.write(" "*string_length)
		sys.stdout.flush()
		time.sleep(pause)

		sys.stdout.write("\b"*string_length)

blinky(strings, .5)

[end code]

My question is that I was recently informed by someone that I could help
free up some memory usage by alleviating the sys.stdout.flush's in the
code, but I need those in order to keep the "blinking" text in place.

Is there any way I can actually free up memory usage in the terms of the
sys.stdout.flush that any of you can notice? I'm simply curious now after
being informed. 

Thanks again,

~Ryan




More information about the Python-list mailing list