[Solved] How do you get python to read a whole text file, not just one line?


Your were breaking out of the loop:
(Btw i added a with statent for opening the file in a more pythonic way)

order = input("Please enter the name of the product you wish to purchase\n")
with open("barcode.txt","r") as myfile:
    details=myfile.readlines() #reads the file and stores it as the variable 'details'
    for line in details:
        if order in line: #if the barcode is in the line it stores the line as 'productline'
            productline=line
            quantity=int(input("How much of the product do you wish to purchase?\n"))
            itemsplit=productline.split(' ') #seperates into different words
            price=float(itemsplit[1]) #the price is the second part of the line
            total=(price)*(quantity) #this works out the price
            print("Your total spent on this product is: " +'£'+str(total))

3

solved How do you get python to read a whole text file, not just one line?