【发布时间】:2016-07-06 07:15:20
【问题描述】:
请帮我解决下面的代码并说明为什么os.makedirs 不起作用?
(请不要注意缩进:它们在原版中是正确的,只是我正在掌握这个网站上的 HTML 编码。)
import os,pprint,sys
while True:
print()
oq=input('Press the first directory: ')
print()
print()
ow=input('Press the next directory/name: ')
print()
p2=input('Continue with next directory? yes or no: ').lower()
if p2=='no':
break
print()
oe=input('Press the next directory/name: ')
print()
p3=input('Continue with next directory? yes or no: ').lower()
if p3=='no':
break
print()
oee=input('Press the next directory/name: ')
print()
p4=input('Continue with next directory? yes or no: ').lower()
if p4=='no':
break
print()
ot=input('Press the next directory/name: ')
print()
p5=input('Continue with next directory? yes or no: ').lower()
if p5=='no':
break
print()
oy=input('Press the next directory/name: ')
print()
p6=input('Continue with next directory? yes or no: ').lower()
if p6=='no':
break
print()
ou=input('Press the next directory/name: ')
print()
p7=input('Continue with next directory? yes or no: ').lower()
if p7=='no':
break
print()
if p2=='no':
os.makedirs(oq+'\\'+ow)
if p3=='no':
os.makedirs(oq+'\\'+ow+'\\'+oe)
if p4=='no':
os.makedirs(oq+'\\'+ow+'\\'+oe+'\\'+oee))
if p5=='no':
os.makedirs(oq+'\\'+ow+'\\'+oe+'\\'+oee+'\\'+ot)
if p6=='no':
os.makedirs(oq+'\\'+ow+'\\'+oe+'\\'+oee+'\\'+ot+'\\'+oy)
if p7=='no':
os.makedirs(oq+'\\'+ow+'\\'+oe+'\\'+oee+'\\'+ot+'\\'+oy+'\\'+ou)
ppp=input('Wannna continue???')
if ppp=='no':
sys.exit()
【问题讨论】:
-
您需要将代码格式化为更易于阅读。像这样将它粘贴成一大堆可能会使通常会回答您问题的人直接跳过它。我建议查看帖子的代码格式帮助部分,然后编辑/重新提交。
-
我希望你不介意,...但我已经处理好了你的缩进。不过,我确实保持每条线与其他线相同。要执行我刚刚所做的,突出显示代码并按 Ctrl-k。
-
“不起作用”在什么情况下?您是否在代码中放置了任何调试消息以查看它实际上进入了那里?还使用
os.path.join()连接路径,和/或os.sep作为分隔符,而不是硬编码`\\`
标签: python