1
即時通訊新的到這個網站,我知道很多人不是很高興,當有人問以前問一個問題。不過,我想問問,儘管之前被問到過,因爲我發現的所有答案對我來說都沒什麼意義(即時通訊是python的新手!),所以我想知道是否有人可以爲我解決這個問題,或者直接糾正我的代碼。閱讀文件的下一行
我在用戶輸入一個GTIN-8代碼的地方編寫了一個代碼,然後它爲該代碼搜索一個csv excel文件,然後讀取有關該產品的適當信息(價格等)並將其打印出來。但是由於某種原因,我無法搜索文件的第二行。這裏是我的代碼:
#csv is imported to read/write to the file
import csv
#Each Product is printed alongside it's GTIN-8 code and Price
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("~ Welcome to Toms bits and bobs ~")
print("Pencil, 12346554, £0.40")
print("50 Staples, 12346882, £1.00")
print("50 Paper Clips, 12346875, £1.20")
print("Large Eraser, 12346844, £1.50")
print("100 A4 Sheets, 12346868, £2.00")
print("100 A3 Sheets, 12346837, £2.50")
print("25 Byro Pens, 12346820, £2.20")
print("Handwriting Pen, 12346899, £5.50")
print("50 Split Pins, 12346813, £0.60")
print("Office Chair, 12346912, £25.00")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
#The file is opened and the user inputs the code for the product they
#wish to find.
file = open("Product_list.csv", "r")
purchase = input(print("Please enter the GTIN-8 code of the product you wish to purchase e.g 12346554"))
line = file.readline()
data = line.split(",")
if data[0] == purchase:
while(line):
print ("Product: ", data[1])
print ("GTIN-8 code: ", data[0])
print ("Stock: ", data[2])
print ("Description: ", data[3])
print ("Price: ", data[4])
line = file.readline()
break
else:
print("Product not found")
file.close()`
在回答Lafexlos - 感謝您的答覆,但刪除它並沒有改變必須休息,搞明白了,雖然現在從,日Thnx的意見;) –
一旦我有15聲譽我會給你一個向上的箭頭:) –
@CoderColin哈哈。謝謝。順便說一句,如果不是這個,那該怎麼辦?如果您願意,我可以在正確的位置編輯。抱歉,我剛看到你的第一條評論。 – Lafexlos