Q:

python - assignment in text document

i have a file and it is made up with different values. and i need to define them and then search through them.
in the file i have - number, number 2, job type, first name, last name.
how would i make it so it will search the hole file for that name or number then bring up the other vaules in that line?
all i have at the moment is opening the file :(, i am stumped.
import csv

fname = input(open("Please enter the name of the file you wish to open: ")

im usign python 3.0

A:

just start with the documentation's example!
import csv
with open('eggs.csv', 'rb') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in spamreader:
        print ', '.join(row)

result:
Spam, Spam, Spam, Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam

in your case:
import csv

value1 = "Spam"

fname = input(open("Please enter the name of the file you wish to open: ")

with open(fname, 'rb') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in spamreader:
        if value1 in row: # if the string of value1 is exactly one of the cells of the row
            print " ".join(row) # printout the full row

if you do your homework well, and read thoroughly the mighty documentation, you'll find out there are better ways to actually work with csv than what I'm suggesting (though starting with what I'm giving, you can make something working fine). 
But here I'm not to write code for you, all I want is to give you a hint so you can get started coding!

