我有以下腳本:函數返回無
def collectUserPrompt():
xml_file = raw_input('Enter the full file path (ex: C:\Users\Stan\Documents\myxml.xml):')
try:
os.path.isfile(xml_file)
print 'good path'
except:
print "Please enter a valid xml file path!"
collectUserPrompt()
multiplier_input = raw_input('Enter XML multiplier (numbers only):')
try:
multiplier = int(multiplier_input)
print 'good multiplier'
except :
print "Please enter a valid integer!"
collectUserPrompt()
return xml_file, multiplier
user_input = collectUserPrompt()
print user_input
當我跑,我得到:
Enter the full file path (ex: C:\Users\LIDMZ3W\Documents\myxml.xml):C:\Users\Stan\Documents\Aptana Studio 3 Workspace\ADFTest\src\Training\nascoUMBY.xml
good path
Enter XML multiplier (numbers only):3
good multiplier
None
它看起來像我每次回國None
,當我試圖從raw_input
函數返回驗證的用戶輸入。
你的'return'是縮進的,所以它在'except'中。您還應該返回遞歸調用的結果。 – Ryan