Ask coding questions

← Back to all posts
How do I make the loading thing in 1 line only?
P0GCHAMPB0i (55)

How do I make the loading thing in 1 line only?

Answered by Bookie0 (6261) [earned 5 cycles]
View Answer
Comments
hotnewtop
Bookie0 (6261)

What do you mean? Do you want it to only show the word Loading with the dots? In that case, you can clear the after each "frame". For that, at the top of the program do import os, and after each "frame" you can add os.system('clear'). :)

Bookie0 (6261)

@B1gB0i Ok, well lmk if you have questions :)

Bookie0 (6261)

@B1gB0i I've already told you, check my first comment.

At the top of the program, add import os, and after each time.sleep(0.01), you can add os.system('clear') which clears the terminal screen.

Dunce (65)

@B1gB0i If you're wanting to know how to clear the text after each frame, I would recommened putting the escape code \033[H in your print statement, this will move the cursor up one line. Or if that doesn't work use \033c instead, this will completely clear the console.

Bookie0 (6261)

@B1gB0i Can you please calm down and not use caps? Please send me the code you're using or a repl. The one posted here doesn't have what I advised you to do. (If you run the repl on this post, it'll have an error as you didn't import time; you'll have to add at the top import time). :)

P0GCHAMPB0i (55)

@Bookie0

print("\033[0;32m")
import time
while True:
  for i in range (1):
        print("Loading")
        time.sleep(0.01)

        print("Loading .")
        time.sleep(0.01)

        print("Loading . .")
        time.sleep(0.01)

        print("Loading . . .")
        time.sleep(0.01)

        print("Loading . .")
        time.sleep(0.01)

        print("Loading .")
        time.sleep(0.01)
IMayBeMe (458)

Two ways,
1) for i in range(1, 5): print('loading' + '.'*i)
2) [print("loading" + '.'*x); for x in range(1, 5)]

Both of them work the exact same but the one line for loop is more readable.

Dunce (65)

It's not one line, but it's cleaner.

loading = "loading"
for i in range(4):
  loading += "."
  
  print(loading)
  time.sleep(0.01)
Dunce (65)

@B1gB0i Why doesn't it work? I just tried it, and it worked fine for me.

Dunce (65)

@B1gB0i You have to import the time module, ya dork :)

P0GCHAMPB0i (55)

@Dunce AHEM AHEM I DON'T WAT IT LIKE DAT

Dunce (65)

@B1gB0i Well how do you want it?

CodeLongAndPros (1624)

Don't do it.
It's unnecessary, hard to read, and takes up time.
If you really want it, you could do:
[print("loading" + '.'*x) for x in range(5)]

CodeLongAndPros (1624)

@B1gB0i
Well actually it would be three lines:

x = ["loading" + '.'*x  for x in range(5)]
for l in x:
  print(x); time.sleep(0.5)