Home > Back-end >  Why is my Python script printing "None" after using a function and using input(print())?
Why is my Python script printing "None" after using a function and using input(print())?

Time:12-24

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.

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)

CodePudding user response:

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): "))

  • Related