小编Fel*_*lix的帖子

使用os.listdir仅显示目录

如何通过os.listdir指定哪个目录来通过,只能将python带到输出目录raw_input

是)我有的:

file_to_search = raw_input("which file to search?\n>")

dirlist=[]

for filename in os.listdir(file_to_search):
    if os.path.isdir(filename) == True:
        dirlist.append(filename)

print dirlist
Run Code Online (Sandbox Code Playgroud)

现在,如果我输入(通过raw_input)当前工作目录,这实际上是有效的.但是,如果我输入其他内容,列表将返回空.我试图划分并克服这个问题,但是每个代码片都按预期工作.

python raw-input os.path

6
推荐指数
1
解决办法
5486
查看次数

标签 统计

os.path ×1

python ×1

raw-input ×1