-2

I am making a command line game engine in python. However, when I attempt to print a command, it newlines and creates a jittery frame.

Adding the end attribute bogs down my computer and nearly crashes the shell. The dupe uses sys.stdout.write('') newline sys.stdout.flush or print'', or print('',end=''). all bog down shell and crash it. print('') doesn't bog down though which is weird.

#this is enough code to demonstrate the problem
while true:
    print('                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         =                                                                              ===                                                                            =====                                                                          =======                                                                        =========                                                                      ===========                                                                    =============    YYYYYYYYYYY                                                 ================================================================================')
#crash issue
import sys
while True:
    sys.stdout.write('mooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo')
    sys.stdout.flush()

I expect the screen to fill, instead it wobbles up and down.

KillerQuow
  • 37
  • 8
  • You probably want to use a library that offers better control over the screen buffer, e.g. `python_prompt_toolkit` or `asciimatics`. Also, for your specific problem, you may want to use `print(text, end='')` (if I understood correctly). – norok2 Jun 24 '19 at 20:54

1 Answers1

0

I am not sure if I understood your question correctly, but I’m thinking you do not want to print a new line with each call to the print() function.

If so, the print function has an optional argument end, that is set by default as \n (this, creating a new line if not specified otherwise). If you don’t want this to happen, you can simply use the print function as:

print(your_argument, end=“”)      

Replacing your_argument with whatever you want to print out.

Stephen
  • 1,072
  • 1
  • 19
  • 33