function - Python sketch not working as intended (reading data from CSV) -


i trying write program runs through csv file of academic papers. csv tab deliminated , in 4 columns (author, date, title, journal)

the idea ask user whether wants search group of papers via author, paper title or journal title (or press q quit), , display results of query user in order: author/s. year. title. journal.

my code runs, retrieves data 'search option' selected. i.e, if choose search author, pull , display authors names match query, doesn't display of other information (the year, title or journal). same other search options (i.e if select journal, pull relevant journals not give me author, date or title of said journal)

any here appreciated! below code.

import csv   def authorsearch():     authorsearch = input("please type author name. \n")     item in author:         if item.find(authorsearch) != -1:             print (item)  def titlesearch():     titlesearch = input("please type in title, \n")     item in title:         if item.find(titlesearch) != -1:             print (item)  def journalsearch():     journalsearch = input("please type in journal, \n")     item in journal:         if item.find(journalsearch) != -1:             print (item)       data = csv.reader (open('list.txt', 'rt'), delimiter='\t')   author, year, title, journal = [], [], [], []  row in data:     author.append(row[0])     year.append(row[1])     title.append(row[2])     journal.append(row[3])   print ("please type in capitals.") searchoption = input("press search author, t search titles or j search journals or press q quit. \n" )  if searchoption == 'a':  authorsearch()  elif searchoption == 't':     titlesearch()  elif searchoption == 'j':     journalsearch()  elif searchoption == 'q':     exit() 

thank helps, it's appreciated!

i have googled , read csv reference page, can't seem head around it. aagin, appreciated!

your issue put info separate arrays...but did because know column numbers...so keep , call number!

everything = [] row in data:     everything.append[row] 

here example title search function:

def titlesearch():     titlesearch = input("please type in title, \n")     row in everything:         title = row[2]         if title.find(titlesearch) != -1:             print row 

so take entire row, , run find() on 3rd column (the 1 said title) , if it's same titlesearch print entire row of information, problem solved!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -