我对python不熟悉 我想要的是能够打印一个文件的内容,我有这样的。。你知道吗
Mashed Potatoes , topped with this and that ...................... 9.99$
同样地
Product_name , description ......................... price
当我将它与只包含产品名称的文件匹配时
Mashed Potatoes
Past
Caesar Salad
etc. etc.
第一个文件的内容顺序不统一 所以我尝试用搜索匹配打印的方法
我希望你能理解我的问题
这就是我尝试过的
import re
content_file = open('/Users/ashishyadav/Downloads/pdfminer-20110515/samples/te.txt',"r")
product_list = open('/Users/ashishyadav/Desktop/AQ/te.txt',"r")
output = open("output.txt" , "w")
line = content_file.read().lower().strip()
for prod in product_list:
for match in re.finditer(prod.lower().strip(), line):
s=match.start()
e=match.end()
print >>output, match.group(),"\t",
print >>output, '%d:%d' % ( s, e),"\n",
我的代码所做的是将第二个产品列表文件与完整内容文件匹配,但只给出产品名称的索引,而不是描述和价格。。你知道吗
我想要的是从产品名称到价格的索引/span。。你知道吗
比如土豆泥——9.99美元(土豆泥-[0:58]),我刚拿到[0:14]
以及任何方式打印的说明和价格使用相同的方法
提前谢谢
如果你需要python中的这个,请告诉我。你知道吗
相关问题 更多 >
编程相关推荐