So to begin I am new to programming in general (3 months or so in) and although learning through books is good I do like to try and apply my knowledge and learn through experience.
At my work our warehouse staff often pick orders wrong so I am trying to develop something that will pull an order list from a .txt file and check it against the picked item. I feel this is a task I can use to consolidate some of my current knowledge whilst also learning new things.
from tkinter.filedialog import askopenfilename
#This splits the order .txt file into a list
def picklist(ordernum):
with open(ordernum, "r") as f:
mylist = [line.strip() for line in f]
return mylist
def test(list):
pickeditem = input("Please scan the first item")
for i in range(len(list)):
if list[i] == pickeditem:
print("Correct item.")
else:
while list[i] != pickeditem:
input("Wrong item! Please scan again:")
if list[i] == pickeditem:
print("Correct item.")
def order():
print("Please pick the order you want to complete")
order = askopenfilename() #gets order .txt from user
pcklist = picklist(order)
print("You pick list is: ",pcklist)
test(pcklist)
order()
So the general idea is to creata a .txt file with a list of item serial codes that need pulling and then get that in python within the order function that I created. I then use the picklist function to split the items that are stored in the .txt file into a list so that I can get the user to scan one item at a time to verify it is the correct one.
This is where I'm trying to call on what is currently called the test function. I want this function to take each item within the list and if it is equal to the item scanned to print that is is the correct item. This works kind of fine, well perfectly fine for the first item.
The problem is getting it to iterate onto the next item in the list. So if item one is 2155 and item 2155 is scanned it will say correct item. The issue is it will then say "Wrong item! Please scan again:" because I assume pythong has now moved onto item 2 in the list. But, if I then input the code for 2 it will say wrong item! Please scan again.
I've tried using list indexing to no avial - maybe I should be doing this in a single function and not splitting it as I am.
I am certainly not looking for anyone to finish the code for me but really point me in the right direction of what I need to learn. The final goal of the project is for it also to hold information regarding the warehouse location for each item, the amount of each item needed, and the ability to pull the picklist off of our internal order system. However, they're things I want to integrate bit by bit as I learn.
I understand this probably is not the slickest, most pythonic code ever but really im after something easy to read, understand and edit in the future.
For now I just need to understand what I need to learn / how I need to think about this issue so that I can check each item in the .txt file provided matches each item scanned by the user.
Thanks in advance.