我試圖檢查我的函數的有效性,我注意到我的兩個函數具有相同的代碼給出兩個不同的輸出。我需要在其中一個條件中更改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)
要重複使用相同的讀者,但一旦讀者閱讀,沒有什麼更多的讀者閱讀,所以第二種方法無關。 –