0

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'])
LesM76
  • 63
  • 1
  • 9

1 Answers1

1

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

Merijndk
  • 1,674
  • 3
  • 18
  • 35
  • that looks to be what I'm after. I'll give it a spin. Thank you :) Then I'll try and work out outputing the individual csv columns to different output boxes. Thanks again – LesM76 Feb 15 '16 at 00:33
  • @LesM76 Yeah. Make sure to put your result online or update your question with your new code if you need more help. – Merijndk Feb 15 '16 at 14:16
  • Hi Merijn, I've tried the above code and I seem to be getting errors, I copied and pasted your code and had no luck and then modified it a bit to see if I had to add some extra data in but still no luck. I'm sure I've done something wrong, the code plus my initial check for a number has been added to the original question. Thank you – LesM76 Feb 15 '16 at 19:07