menator Posted May 1, 2011 Share Posted May 1, 2011 I seem to be having trouble figuring out where to use the capitalize function in my code; any help would be great! import MySQLdb # Connect to the database try: db = MySQLdb.connect(host="xxxxx", db="xxxxx", user="xxxxx", passwd="xxxxx") except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit(1) def mycats(alive=""): c = db.cursor() if(alive != "a" and alive != "d"): c.execute("select name from cats") else: if(alive == "a"): alive = "yes" if(alive == "d"): alive = "no" c.execute("select name from cats where alive = \"%s\"" % (alive)) names = c.fetchall() for name in names: print "%s" % (name) alive = "" while alive != "e": print "To view cats:\n \ a = alive, d = dead, and all = all.\n \ To exit type in e" alive = raw_input(": ") if(alive != "a" and alive != "d" and alive != "all" and alive != "e"): print"" print"" print "Only valid entries are\n a = \"alive\" \n d = \"deceased\" \n all = \"all\" \n e = \"exit\"" print "" continue if(alive =="e"): print "Goodbye!" break else: print "" if(alive == "a"): print "My cats that are alive\n" elif(alive == "d"): print "My cats that are deceased\n" else: print "This is all of my cats that are alive and dead\n" mycats(alive) print "" print"" Link to comment https://forums.phpfreaks.com/topic/235293-python-and-capital-letters/ Share on other sites More sharing options...
menator Posted May 2, 2011 Author Share Posted May 2, 2011 Had to change the tuple to a list to get it to work names = c.fetchall() Mylist = [] for name in names: Mylist.append("%s" % (name)) for pet in Mylist: print pet.capitalize() Link to comment https://forums.phpfreaks.com/topic/235293-python-and-capital-letters/#findComment-1209459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.