Skip to content
Sign upLog in
← Back to Community

The Slow Print

Profile icon
Muffinlavania

Introducing: Delayed Printing!

This isnt a very new thing... But some people may not know about it so here it is!
Delayed Printing is printing out a string slowly, one character at a time. Here is how you can do it!

The Simple Way

import sys,time def delprint(text,delay_time): for character in text: sys.stdout.write(character) sys.stdout.flush() time.sleep(delay_time)

The Other way

import sys,time def delprint(text="Type a string in",delay_time=.05): for character in text: sys.stdout.write(character) sys.stdout.flush() time.sleep(delay_time)

Line by Line Breakdown

Line 1)

def delprint(text,delay_time)

This line is different for the 2nd way of doing this. The 2nd way has one more thing, a default definition. The two arguments, text and delay_time already have a default definition, so if you dont fill them in when calling the function, it will not error.
But in this simpler version , all this means is that when calling this function, you have to fill in two arguments, the text you want to be "slow printed", and the delay time between each character

Line 2)

for character in text:

This line is the same for both versions. This for loop will go through each character in the text that was entered into the function

Line 3/4)

sys.stdout.write(character)
sys.stdout.flush()

These two lines is where the printing happens. I dont really know why printing does not work, but this gets the job done. The sys.stdout.write part writes the variable and the sys.stdout.flush() part makes the variable flush in the module(whatever that means..)

Line 5

time.sleep(delay_time)

This line of code is where it waits a bit before printing out the next letter. In the function you will put in how long you want it to wait between each letter, or in the other version it's default is .05

Calling the Function

  1. Simple way
delprint("I like turtles",.05) #printing i like turtles with a 0.05 delay between each letter
  1. The other way
delprint("I LOVE turtles") #Filling in the other part is not needed, it is already 0.05

Check out the below repl for the finished code

You can do A LOT with this function, for an example look here, i added a lot more things to the delprint() function in this file!
If you have any questions, comment them below! Im sure someone will answer it, either me or some random guy...

And also if you made a tutorial on this, I didn't copy it okay?

EDIT

i redid the whole tutorial, i think its better.. And also a suggestion is to add this to the end of you function, print(""). This will make it so that it indents after printing out the text. Your code should look like this, or of course with the "other way" it will be a bit different

import sys,time def delprint(text,delay_time): for character in text: sys.stdout.write(character) sys.stdout.flush() time.sleep(delay_time) print("")
Voters
Profile icon
DesmondMcDonald
Profile icon
LucasPione
Profile icon
Venombite201
Profile icon
JermaineAdjaido
Profile icon
johnnyfrancis
Profile icon
programmeruser
Profile icon
PennyK
Profile icon
Veneficus256
Profile icon
Muffinlavania
Comments
hotnewtop
Profile icon
Polarpig109

how would you make the delprint an input?

Profile icon
Muffinlavania

@Polarpig109
well the easiest way is to just put input right after it lol, since if you just put somethingidk=input() then the input doesnt show anything so it looks like its the delprint which is being the input
and if you just put return input() at the end of the delprint function it should work i think

Profile icon
Venombite201

would there be a way to make it so when you like type space when its writing it automatically skips it and shows the full text?

Profile icon
Muffinlavania

@AdrianAsmar
actually, yes
basically you make another thread, which takes a getkey
then in the printt function, you put the time.sleep(delay_time) in an if statement that is for the key you want.
its kinda hard to explain so like heres an example i did lol: https://replit.com/@Muffinlavania/Skip-da-printt#main.py

Profile icon
RahulChoubey1

It doesn't work because you need to put flush=true into the print function. It won't flush otherwise.

Profile icon
Muffinlavania

@RahulChoubey1
holyyyyyyyy this post is so old lol
but it works cause we got sys.stdout.flush(), which is the same as flush=True? (idk there isnt even print in this lol)

Profile icon
RahulChoubey1

@Muffinlavania
Ik, but in your desc, it says that you were having trouble wth your print not flushing.

Profile icon
Muffinlavania

@RahulChoubey1
oh yea thats true
i kinda gave up on the print method though lol

Profile icon
winnerwannabe2

how do u do this in html?

Profile icon
fluffyyboii

Why not just use "print(character, end='')"?

Profile icon
Muffinlavania

I completely redid the whole thing! Now its better i hope..

Profile icon
Highwayman

Why am I developing a muffin programming Lang with everyone but u this feels so wrong

Profile icon
Muffinlavania

@Highwayman
i mean... i really only know python and html... that really kinda it...

Profile icon
Highwayman

@Muffinlavania
ik ik... it just still feels so wrong....

Profile icon
Bookie0

um simpler way:

import sys, time st = 0.04 # i called it sp for slowPrint def sp(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(st) print() # and change the st variable to what you want sp ("Hello")
Profile icon
Muffinlavania

@Bookie0
yea... i said that you only needed one variable, and the type and the other stuff was not needed...