【发布时间】:2020-06-30 15:04:07
【问题描述】:
import os
def new_directory(directory, filename):
# Before creating a new directory, check to see if it already exists
if os.path.isdir(directory,mode="w+") == False:
os.mkdir(directory)
# Create the new file inside of the new directory
os.chdir(directory)
with open(filename) as file:
pass
# Return the list of files in the new directory
return os.listdir(directory)
print(new_directory("PythonPrograms", "script.py"))
我的代码显示此错误:
Traceback (most recent call last):
File "C:\Users\Toshiba\Desktop\new.py", line 16, in <module>
print(new_directory("PythonPrograms", "script.py"))
File "C:\Users\Toshiba\Desktop\new.py", line 14, in new_directory
return os.listdir(directory)
FileNotFoundError: [WinError 3] The system cannot find the path specified:
'PythonPrograms'
[Finished in 0.1s]
我试过不使用 mode="w+" 然后我得到另一个错误..
【问题讨论】: