PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

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

 September 18, 2022     function, input, printing, python     No comments   

Issue

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)

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



Answered By - Antoine Delia
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing