Skip to content
← Back to Community
How do I make the loading thing in 1 line only?
Profile icon
P0GCHAMPB0i

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

Answered by Bookie0 [earned 5 cycles]
View Answer
Voters
Profile icon
bot111222
Profile icon
P0GCHAMPB0i
Comments
hotnewtop
Profile icon
Bookie0

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'). :)

Profile icon
P0GCHAMPB0i
Profile icon
Bookie0

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

Profile icon
P0GCHAMPB0i

@Bookie0 DO IT

Profile icon
Bookie0

@B1gB0i huh?

Profile icon
P0GCHAMPB0i

@Bookie0 TELL ME THE CODE

Profile icon
Bookie0

@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.

Profile icon
Dunce

@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.

Profile icon
P0GCHAMPB0i

@Bookie0 IT WONT WORK

Profile icon
Bookie0

@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). :)

Profile icon
P0GCHAMPB0i

@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)
Profile icon
IMayBeMe

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.

Profile icon
Dunce

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

loading = "loading" for i in range(4): loading += "." print(loading) time.sleep(0.01)
Profile icon
P0GCHAMPB0i

@Dunce oh on

Profile icon
P0GCHAMPB0i

@Dunce it won't work

Profile icon
Dunce

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

Profile icon
P0GCHAMPB0i

@Dunce OK LEMME DO IT

Profile icon
P0GCHAMPB0i

@Dunce
image
WHATS THIS?

Profile icon
Dunce

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

Profile icon
P0GCHAMPB0i

@Dunce OH U IDIOT

Profile icon
P0GCHAMPB0i

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

Profile icon
Dunce

@B1gB0i Well how do you want it?

Profile icon
CodeLongAndPros

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)]

Profile icon
P0GCHAMPB0i

@CodeLongAndPros but i want to

Profile icon
CodeLongAndPros

@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)