This is what I am trying to do, I am using the command prompt
import time
mess = list("StackOverflow")
def myFunc():
for i in xrange(1000):
for k in mess:
print k
time.sleep(0.1)
if __name__ == '__main__':
myFunc()
I am trying to span the display across the cmd prompt, Basically try a matrix effect, how do i go about this..
Take a look at the screenshot: https://i.sstatic.net/zjspP.png
All I want to know is, if its possible to print vertically on all the columns at once, and then the chars dropping down(not horizontal)
2 Answers 2
By default, print includes a newline.
You can specify that it not do so by adding a comma to the end of the print statement.
And then, at least on my system, you run into the problem of buffered output.
So I included a call to flush stdout.
import sys, time
mess = "StackOverflow"
def myFunc():
for i in xrange(1000):
for k in mess:
print k,
sys.stdout.flush()
time.sleep(0.1)
if __name__ == '__main__':
myFunc()
Equivalent code for Python 3:
import sys, time
mess = "StackOverflow"
def myFunc():
for i in range(1000):
for k in mess:
print(k, end=" ")
sys.stdout.flush()
time.sleep(0.1)
if __name__ == '__main__':
myFunc()
4 Comments
EDIT: If all you want is to print it out like that, then simply do this:
import sys
strng = "S t a c k O v e r f l o w"
for i in range(10000):
sys.stdout.write(strng)
Have you tried simply doing this?
import time, sys
stackOverflow = "stackoverflow"
for i in range(10000):
for char in stackOverflow:
for j in range(3):
sys.stdout.write(char + " ")
time.sleep(0.1)
print("") #Newline
list("text")... A string is iterable in python.for char in "Hello!": print(char). If you're trying to print multiple strings:for strng in ("hello", "hi", "how are you"): print(strng).