-2
我正在嘗試在True循環中執行一系列檢查以查看文件夾是否存在或用戶錯誤。在我的文件夾中,我有兩個文件夾A和B.我將要求用戶輸入文件夾名稱。檢查用戶在Python中輸入的文件夾是否存在
from os.path import exists
folder1_2 = input('Enter folder name: ')
i = (folder1, folder2)
while True:
i = raw_input()
does_it_exist = os.path.exists(i) # True/False
if does_it_exist == False:
print("The folder does not exist")
continue
if os.listdir(".") == False:
print("folder not found")
continue
if i('A', 'B') == False:
print("not the same folder or user error")
continue
break
print("All tests passed successfully!")
return [folder1_2]
您似乎忘記提問了。除了縮進之外,這段代碼有什麼問題? –
'os.listdir(「。」)== False'幾乎沒有用......'os.listdir'返回一個列表,所以它不會'False' –
也'如果我('A','B') ==假:「是錯的。 '我'是一個字符串,而不是一個函數。請閱讀有關python的更多信息。 –