我想在同一个目录下创建一个文件夹,哪里出错了?
def selection():
print "Content Profiling"
print "~~~~~~~~~~~~~~~~~"
print " 'G', 'PG13', 'NC16', 'M18', 'R21' "
selectionInput = raw_input("Please select your content profile")
if selectionInput == "G":
root = os.curdir()
path = root+"/G"
os.makedirs( path, 0755 );
输出:
Traceback (most recent call last):
File "C:\Python27\guicmd.py", line 44, in <module>
selection()
File "C:\Python27\guicmd.py", line 38, in selection
root = os.curdir()
TypeError: 'str' object is not callable
请您参考如下方法:
os.curdir不是函数而是常量字符串。只是作为一个值:
root = os.curdir
当您这样做时,您可以使用 os.path.join 改进您的代码.
path = os.path.join(os.curdir, "G")
os.makedirs(path, 0o755)
