0

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)

asked Jun 30, 2012 at 19:20
12
  • "I am trying to span the display across the cmd prompt,"... What do you mean? Commented Jun 30, 2012 at 19:23
  • i mean the output shud cover the whole cmd prompt window... the above display on one line, i want the same thing to be repeated accross the window. Commented Jun 30, 2012 at 19:24
  • 2
    You dont need to do 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). Commented Jun 30, 2012 at 19:26
  • 1
    And what's wrong with what you have now? Is it not working as expected? If so, what is wrong with it? Commented Jun 30, 2012 at 19:26
  • 1
    @Whiskey: Yeah I should have mentioned that. I think you may be SOL. Alternatively, you could try using a GUI package (like Tkinter, or WxPython) to emulate a console window... although at that point it may be getting a little ridiculous. Commented Jun 30, 2012 at 20:08

2 Answers 2

1

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()
answered Jun 30, 2012 at 19:26
Sign up to request clarification or add additional context in comments.

4 Comments

I am sorry i think m not able to explain clearly.... I want a matrix effect to be created with the string passed... the string is "Stackoverflow", i want s s s s s t t t t t a t t t t c c c c c k k k k k o o o o o ......... and so on.. all at the same time dropping down..accross the window
Please take a look at this.. i.imgur.com/J4p58.png I want the chars to fall down vertically from top to bottom.. all at once...
OK. Thank you for the clarification. The code I posted produces the expected output. However it does not do so in the order you specify. I am not aware of anything that produces output in such an order.
Thanks bernie... for trying to help :)
0

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
answered Jun 30, 2012 at 19:29

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.