小编Ron*_*gan的帖子

在Python中读取目录的安全方法

try:
    directoryListing = os.listdir(inputDirectory)
    #other code goes here, it iterates through the list of files in the directory

except WindowsError as winErr:
    print("Directory error: " + str((winErr)))
Run Code Online (Sandbox Code Playgroud)

这工作正常,我已经测试过,当目录不存在时它不会窒息而死,但我正在读一本Python书,我应该在打开文件时使用"with".有没有一种首选方式来做我正在做的事情?

python directory system-calls

5
推荐指数
1
解决办法
6383
查看次数

标签 统计

directory ×1

python ×1

system-calls ×1