python - How do I make my program give me the value of a certain cell in a CSV? -


i having problems trying make program find cell in csv file. program ask 8 digit number. if in csv file, row should written text file. should proceed ask user how of product want buy. quantity multiplied give final price. price written variable named totalprice.

my initial problem quantity since cannot retrieve third column of row of entered gtin-8 number in csv file.

my code is:

import csv import sys import re import os  additem = "" gtinnum = "" quantity = 0 totalprice = 0 restart = ""  f = open("chocolatecsv.csv", "rt")  def restart():     restart = input("would restart? y/n")      if restart.lower() == "y":         gtinquestion()     else:         print(receiptcont)         sys.exit()  def quantityquestion():     quantity = input("how like?")   def scangtin():     global rows     rows = re.split('\n', f.read())     global receiptcont     receiptcont = receipt.read()     index, row in enumerate(rows):         global cells         cells = row.split(',')         if gtinnum in cells:             receipt.write(receiptcont)             receipt.close()             quantityquestion()  def gtinquestion():     global gtinnum     global receipt     receipt = open("receipt.txt", "r+")     gtinnum = input("please enter gtin-8 code of product order:")      if gtinnum.isdigit() == false or len(gtinnum) != 8:         gtinquestion()     elif gtinnum.isdigit() == true , len(gtinnum) == 8:         scangtin()   gtinquestion() 

you iterate through lines of csv file , return particular column of row contains 8 digit number:

import csv  def get_row(filename, number, column):     open(filename, 'r') f:         row in csv.reader(f):             if str(number) in row:                 return row[column+1] 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo