【发布时间】:2015-02-12 17:19:01
【问题描述】:
我有两个文件:
答:
John
Kevin
Richard
乙:
Manager
Salesperson
Doctor
我正在尝试同时从两个文件中读取行并打印以下内容:
输出:
John is a Manager
Kevin is a Salesperson
Richard is a Doctor
我尝试使用 contextlib.izip 包,但它不起作用。
代码:
with open('name') as names:
with open('job') as jobs:
for names1 in names:
jobs1 = jobs.readlines()
print names1 + jobs1
但这会引发错误
`TypeError: cannot concatenate 'str' and 'list' objects`
我也尝试过使用 contextlib 包,但没有成功。
【问题讨论】: