I'm not after any specific code, just a point in the right direction. As I'm new to this csv thing and a bit stuck.
I have a csv file that contains a column of 'Order numbers', Part Description, Quantity, Drawings:
1) What I'm aiming to do is enter the Order number into a text box.
2) Search the csv file for that number and display the entire row, however I want each field in a different output box, a quantity box, a description box etc. However at the moment I'm happy to have the entire row print into a single box just so I can get things working.
Currently I have got my program to load the csv ok and print the entire csv file to a text box correctly, this is just the next step.
Do I need to read the order number and save it as a variable, then somehow use that variable in the csv code ?
Note: this is being made with tkinter.
def DoASearch():
try:
print(int(sonumber.get()))
except ValueError:
messagebox.showwarning("Fail !!", "Please enter a valid Shop Order number.")
sonumber2=sonumber
with open("lesspreadsheettest.csv") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
sonumber2=(row['Shop Order'])
if sonumber2 == number:
print(row['Shop Order'], row['Part Number'], row['Description'])
So you just want to read out the csv like:
import csv
var number = 100
with open('names.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
var x = row['order']
if x == number:
print("We have a Match")
You need to asign the number you get from the input to the var number