【发布时间】:2014-07-05 20:41:23
【问题描述】:
我有:
master = open('master.txt', 'r')
transaction = open('transaction.txt', 'r')
master_list = []
employee_list = []
for line in master:
# split the line
record = line.split(',')
# extract id from record
emp_id = record[0]
# add id to list
employee_list.append(emp_id)
for li in transaction:
# split the line
rec = li.split(',')
i_d = rec[3]
print(i_d)
这按预期工作并输出
001
001
001
001
001
002
002
002
002
002
003
003
003
003
003
004
004
004
004
004
005
005
005
005
005
但是如果我在这样的嵌套循环中使用 if 语句:
for li in transaction_file:
# split the line
rec = li.split(',')
i_d = rec[3]
if i_d == emp_id:
print(emp_id)
我只得到 001 001 001 001 001
这是为什么?
【问题讨论】:
-
@akonsu 你在拖钓吗,兄弟?