Python program to search for specific strings in hash values (coding help)

Posted by Diego on Stack Overflow See other posts from Stack Overflow or by Diego
Published on 2010-05-13T04:09:25Z Indexed on 2010/05/13 4:14 UTC
Read the original article Hit count: 187

Filed under:
|
|
|
|

Trying to write a code that searches hash values for specific string's (input by user) and returns the hash if searchquery is present in that line.

Doing this to kind of just learn python a bit more, but it could be a real world application used by an HR department to search a .csv resume database for specific words in each resume.

I'd like this program to look through a .csv file that has three entries per line (id#;applicant name;resume text)

I set it up so that it creates a hash, then created a string for the resume text hash entry, and am trying to use the .find() function to return the entire hash for each instance.

What i'd like is if the word "gpa" is used as a search query and it is found in s['resumetext'] for three applicants(rows in .csv file), it prints the id, name, and resume for every row that has it.(All three applicants)

As it is right now, my program prints the first row in the .csv file(print resume['id'], resume['name'], resume['resumetext']) no matter what the searchquery is, whether it's in the resumetext or not.

lastly, are there better ways to doing this, by searching word documents, pdf's and .txt files in a folder for specific words using python (i've just started reading about the re module and am wondering if this may be the route, rather than putting everything in a .csv file.)

def find_details(id2find):
    resumes_f=open("resume_data.csv")
    for each_line in resumes_f:
        s={}
        (s['id'], s['name'], s['resumetext']) = each_line.split(";")
        resumetext = str(s['resumetext'])
        if resumetext.find(id2find):
            return(s)
        else:
            print "No data matches your search query. Please try again"

searchquery = raw_input("please enter your search term")
resume = find_details(searchquery)
if resume:
    print resume['id'], resume['name'], resume['resumetext']

© Stack Overflow or respective owner

Related posts about python

Related posts about hash