我正在尝试在 Python 中打开一个 .log 扩展文件,但我一直遇到 IOError。我想知道这是否与扩展有关,因为显然,进入该循环的唯一方法是目录中是否存在“some.log”。
location = '/Users/username/Downloads'
for filename in os.listdir(location):
if filename == 'some.log':
f = open('some.log', "r")
print (f.read())
追溯:
f = open('some.log', "r")
IOError: [Errno 2] No such file or directory: 'some.log'