python-2.6 - Python:一次打开多个文件
问题描述
我正在使用 python 2.6.6 python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
下面是 script.py 文件,一次打开 2 个文件时出现问题。
import os
path = '/home/test/testData/log/'
os.chdir(path)
k = 0
word = 'Log ends'
filename1 = 'test.log'
filename2 = 'tes2.log'
with open(filename1) as firstFile, open(filename2) as secondFile:
for line in firstFile:
if word in line:
print(line)
当我运行脚本时出现错误
蟒蛇脚本.py
File "script.py", line 11
with open(filename1) as firstFile, open(filename2) as secondFile:
^
SyntaxError: invalid syntax
解决方案
推荐阅读
- javascript - Phaser 3 对撞机无限开火
- python - Sagemaker 回归 - ValueError:无法格式化输入
- java - Need to eliminate the duplicate schema from two different list
- angular - 如何根据角度10中的条件设置选择
- javascript - 如果单击/选择子选项,则在鼠标移出时保持子菜单打开
- android - AVD Pixel_3a_API_28 的模拟器进程被杀死
- javascript - 弹出选项卡的第二个选项中的内容不显示任何内容
- python - 为什么我的冒泡排序不能正常工作?
- reactjs - 调度清除我所有的数据表单输入reactjs
- python-3.x - Python:sqlalchemy - 仅映射结果