我试图检查我的函数的有效性,我注意到我的两个函数具有相同的代码给出两个不同的输出。我需要在其中一个条件中更改if条件,但我也需要确保它们都正常工作。为什么这两个相同的函数创建两个输出过程?
data_out = open("mentees_all_attributes.csv", "rU")
reader = csv.reader(data_out)
next(reader,None)
def primaryWithParticipatedCounts(jobs, count):
for line in reader:
cells = line
new_cell = cells[0], cells[6], cells[7], cells[8], cells[9], cells[
10] # name, # of participation, primary occupation/industry, secondary occupation/industry
if int(new_cell[1]) > 0: # Isolate all the participants with more than 0
primary = new_cell[2]
if primary == jobs:
count += 1
return jobs, count
print primaryWithParticipatedCounts(A012,a012counts)
def primaryWithoutParticipatedCounts(jobs, count):
for line in reader:
cells = line
new_cell = cells[0], cells[6], cells[7], cells[8], cells[9], cells[
10]
if int(new_cell[1]) > 0:
primary = new_cell[2]
if primary == jobs:
count += 1
return jobs, count
print primaryWithoutParticipatedCounts(A012,a012counts)
可以返回输出为:
('[A012]', 3)
('[A012]', 0)
要重复使用相同的读者,但一旦读者阅读,没有什么更多的读者阅读,所以第二种方法无关。 –