我正在嘗試爲倉庫管理項目創建一個目錄編輯器,但每次嘗試創建一個已創建的新文件夾,而不是處理像我在elif塊中指定的問題時,它會給我這個錯誤:我的Python邏輯出了什麼問題?
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:/Users/User_Name/Documents/Warehouse_Storage/folder_name'
據我所知,我的if語句的基本邏輯沒有錯。
這裏是我的代碼:
if operation.lower() == "addf" :
name = input("What would you like to name your new folder? \n")
for c in directory_items :
if name != c :
os.makedirs(path + name + "/")
operation_chooserD()
elif name == c:
print("You already created a folder with this name.")
operation_chooserD()
您需要首先檢查** all **'directory_items'。這不是因爲**第一**不相等,** **(或任何其他)不能相等。 –