CSV 파일에서 특정 키워드를 검색하고 전체 키워드가있는 경우 전체 행에서 데이터를 가져와야합니다. file 나는 학교 일정 때문에 큰 편입니다.CSV 파일 열에서 키워드 검색하기
import csv
with open('plan.csv', 'rt', encoding='windows 1250') as fileinput:
# In the code below I first create a list of groups, skipping
# duplicates, so that user can later select a group to show it's
# details.
reader = csv.reader(fileinput, delimiter=';')
groups = []
#filling up the list with groups
for row in reader:
if row[12] in groups:
continue
elif row[12] is '':
continue
else:
groups.append(row[12])
# Just to make sure there's something in 'groups'
print(groups[1:])
# Then I'm asking a user to select the group.
# user_choice = input('Group?')
# setting up user_choice to make things simpler for testing
user_choice = '3I4'
# The last part is searching groups column (column index 12) for a
# specific group and if found – print whole row and continue
# the search.
for row in reader:
if row[12] is user_choice:
print(row)
continue
else:
print('not found')
코드의 마지막 부분을 실행 한 후에는 콘솔 출력이 전혀 표시되지 않고 group 행도 "not found"도 표시되지 않습니다.
그래서 질문은 무엇입니까? –
죄송합니다. 편집했습니다. –