2017-03-16 82 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. ") 
相关问题