2017-03-16 81 views
-1

如何將我在文本文檔中找到的一行設置爲某個變量,以便我可以對其進行處理,如打印該行或分割該特定行。 python 3.4.6如何在文本文檔中將變量設置爲變量Python 3.4.6

+0

你的問題是什麼?打開文件?找到線?存儲它?你有嘗試過什麼嗎? – Kroltan

+0

我知道如何打開文件並獲取代碼以找到該行,但我無法獲取變量=我在文本文檔中找到的行 –

+0

您能否顯示您的代碼? (只有與問題有關的部分,如果整個程序很大,請參閱如何創建[mcve])使用問題左下角的「編輯」按鈕進行修改。將代碼粘貼到那裏 – Kroltan

回答

0
recfile = open('/home/pi/Desktop/Recipt.txt', "a") 
barfile = open('/home/pi/Desktop/Barcodes.txt').read() 

if barcode in barfile: 
    print("Your product has been found. ") 
    while barcode in barfile: 
     amount = input("How many do you want? ") 
     print(barfile) 

else: 
    print("Your product was not found on our systems. ") 
相關問題