这是我的代码:
import os
if os.path.exists(r'C:\Genisis_AI'):
print("Main File path exists! Continuing with startup")
else:
createDirs()
def createDirs():
os.makedirs(r'C:\Genisis_AI\memories')
Run Code Online (Sandbox Code Playgroud)
当我执行它时,它会抛出一个错误:
File "foo.py", line 6, in <module>
createDirs()
NameError: name 'createDirs' is not defined
Run Code Online (Sandbox Code Playgroud)
我确定它不是拼写错误,我没有拼错函数的名称,为什么我得到一个NameError?
我有一个小问题.
我有以下功能:
def getCommands():
for file in os.listdir(com_dir):
if file.endswith(com_ext):
z = string.strip(file, '.gcom')
print z
Run Code Online (Sandbox Code Playgroud)
在目录(定义方com_dir)中有三个文件.
a.gcom
b.gcom
c.gcom
跑步的时候 getCommands()
输出如下:
a
b
显示文件a和b,但是,未显示c,所有文件都在目录中,并且所有文件都使用相同的文件扩展名:.gcom这也是com_ext可变的.
有没有人有任何提示,为什么文件c没有显示?
旁注:输出中似乎应该有一个空白区域c但是我不确定这是否在手头的问题中有任何部分并且不仅仅是脚本中其他位置的意外空间.