Querying csv with raw_input in Python -


i'm new programming decided take on python.

i have csv file logged hours users looks (but containing around 200 rows):

user,project,hours
user1,projecta,5
user1,projectb,10
user2,projecta,7
user2,projectb,12`

i'd extract data it, through several raw_inputs dependant on previous. eg. start asking if you'd want see full list, if yes print , close there. if answer no, move on next raw_input, eg. enter user you'd see.

i've code, know it's still basic, i'm newbie this, haven't been able figure out solution. appreciated..

import csv reader = csv.reader(open("loggedhours.csv", "rb")) team = raw_input("do want see detailed team numbers? y/n: ")  if team =="y":     user, project, hours in reader:         print user, project, hours  else:     print "ok"     print ""  user = raw_input("enter user id wish check: ")  if user == user in reader:     user, project, hours in reader:         print user else:     print "ok" 

there's line missing before second raw_input, make program finish.

but on first part i'm getting right results when answer == y, don't right thing when answer != y. else part not functioning.

it's obvious there mistakes there, if direct me right path appreciated!

you build dict rows of csv.

teams = {} reader = csv.reader(open("loggedhours.csv", "rb")) team in reader:     teams[team[0]] = (team[1], team[2])  def print_teamnumbers():     user in teams:         print "%s: %s" % (user, teams[user])  def specific_lookup(user_id):     print teams.get(user_id, "user not found")  

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -