Hey all
A few questions regarding a database searching and sorting program that I've been asked to write:
So far I've got this, and I don't think it's very good...it's not close enough to the end goal at any rate:
Code:
# main program starts here!!!
#declare empty lists to hold the names, dates, titles and journals
author=[]
year=[]
title=[]
journal=[]
test=[]
f = open("complete authors.txt", "r", 0)
f.readline()
for line in open('complete authors.txt','r').readlines():
line = f.readline().rstrip('\n').split("\t")
try:
author.append(line[0])
year.append(line[1])
title.append(line[2])
journal.append(line[3])
except IndexError:
print ""
f.close()
#now sort the lists
author.sort()
title.sort()
journal.sort()
year.sort()
# print out our ordered lists
print "Authors:"
for a in author:
print a
print "\nYear:"
for d in year:
print d
print "\nTitle:"
for t in title:
print t
print "\nJournal:"
for j in journal:
print j
So that prints out the list of journals authors etc, and sorts them nicely, which is all fine.
I'm short on a few counts:
Firstly, I need to make a user input function so that where the input is as follows:
Search on author (A = ***) or journal (J = ***), where *** is any string [Q = quit]:
Secondly, I need to store the data in list format, as follows:
List of journals (each journal's 'index' is its position in the list)
List of authors (each author's 'index' is its position in the list)
List of papers (each paper's entry is its title, year published, the index of each author(s) and the index of the journal; in this way the name of each journal and author is only stored in one place).
The file is tab delimited and the headings are author, year, title, journal...not very original.
Any help would be much appreciated...I've been told that a good way to do it would be to use a dictionary to define the author against all the other information, but I don't understand how to make a dictionary work for me in this case...
Cheers everyone, sorry for the long message!
Rob