Skip to content
← Back to Community
How to not print None
Profile icon
OldWizard209
st = 0.03 def sp(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(st) print()

So if i do sp(input("Enter Password"))

I get None in the console,

how to fix it???

Voters
Profile icon
RaquellSenanaya
Profile icon
OldWizard209
Comments
hotnewtop
Profile icon
[deleted]

Hello. This is because input is not clearly defined as a string here!
So, after you define sp(str) and print(), you should NOT directly code

sp(input("Enter Password")

You should first code:


a = str(input("Enter Password"))
sp(a)


This should work out fine. Hope it helps!

Profile icon
SeamusDonahue

input already returns a string with whatever the user typed. @dhruvkumarrajan

Profile icon
[deleted]

@SeamusDonahue
yeah, thanks for pointing it out! :)

Profile icon
OldWizard209

Thanks, it worked out right :) @dhruvkumarrajan

Profile icon
[deleted]
Profile icon
SeamusDonahue

just do print(letter,end="",flush=True)
sys is not needed here, Idk if that will fix it, but I do know that optimization is possible

Profile icon
SeamusDonahue

this is if your working in python 3, in 2 I cant help you.

Profile icon
OldWizard209

Its working. Thanks @SeamusDonahue

Profile icon
OldWizard209

To be fair, I will have to mark the first answer as correct. I am sorry if that offends you. :) @SeamusDonahue

Profile icon
SeamusDonahue

no, it's fine. It didn't answer the question here, but something else did, that's just how it works :) @abdullahrajput9

Profile icon
RYANTADIPARTHI

for one thing. You need to name whether it is a str or a int. either of them specifying will remove the none.

Profile icon
OldWizard209

Yup, its working now. Thanks @RYANTADIPARTHI

Profile icon
OldWizard209

To be fair, I will have to mark the first answer as correct. I am sorry if that offends you. :) @RYANTADIPARTHI

Profile icon
RYANTADIPARTHI
Profile icon
OldWizard209