Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my Python script printing "None" after using a function and using input(print())?

This is my code:

def videoConv(sourceDir, targetDir):
videoSourceDeclaration(sourceDir, targetDir)
input(print("\nis this correct?\n[y]/[n] (yes or no): "))

which prints this:

is this correct?
[y]/[n] (yes or no):
None

How can I stop it from printing "None"? I’ve read that I should use return, but I’m not really sure what I should do.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Also, this is the whole videoSourceDeclaration function:

def videoSourceDeclaration(sourceDir, targetDir):
sourceDir = input("Input source directory (leave blank for default): ")
os.system('cls||clear')
os.chdir("..")
print("source directory: " + os.getcwd())
targetDir = input("\nInput target directory (leave blank for default): ")
if targetDir == "":
    if platform == "linux":
        targetDir = ("~\\videos")
        # not sure of the linux dir, change later and add macos")
    elif platform == "win32":
        targetDir = ("c:\\" + "users\\" + getpass.getuser() + "\\" + "videos")
if targetDir == ("~\\videos") or ("c:\\" + "users\\" + getpass.getuser() + "\\" + "videos"):
    isTargetDirDefault = True   
    os.system('cls||clear')
print("source directory: " + os.getcwd() + "\ntarget directory: " + targetDir)

>Solution :

You are mixing a few things here.

In order for you to print the input of the user, you must first get it. You did it correctly with the input() function, but this will return you the result. That’s what you need to print.

So you should change your code from this:

input(print("\nis this correct?\n[y]/[n] (yes or no): "))

to this

print(input("\nis this correct?\n[y]/[n] (yes or no): "))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading