scarecrow- scarecrow- - 7 months ago 18
Python Question

python input parameters getting added

How do you add prompt parameter in the input function for python

def getUserFileNameInput(self, s):
FileName = input("Please enter the file name and path for " % s)

test = t()
test.getUserFileNameInput("my.txt")


File "C:\Python34\try.py", line 13, in getUserFileNameInput
FileName = input("Please enter the file name and path for " % s

Answer

You aren't concatenating strings correctly, you have, at least, two ways to do it :

myNewString = "Here's my old string : %s" % oldString

or

myNewString = "Here's my old string : " + oldString

So in your example you should do :

def getUserFileNameInput(self, s):
    FileName = input("Please enter the file name and path for " + s)

test = t()
test.getUserFileNameInput("my.txt")

or

def getUserFileNameInput(self, s):
    FileName = input("Please enter the file name and path for %s" % s)

test = t()
test.getUserFileNameInput("my.txt")
Comments