Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting the contents and index location of one file by matching it with other file using python
    primarykey
    data
    text
    <p>I'm new to python What I want is to be able to print content of a file I have like this..</p> <blockquote> <p>Mashed Potatoes , topped with this and that ...................... 9.99$</p> </blockquote> <p>similarly</p> <blockquote> <p>Product_name , description ......................... price</p> </blockquote> <p>when I match it with a file containing only Product_names</p> <blockquote> <p>Mashed Potatoes</p> <p>Past</p> <p>Caesar Salad</p> <p>etc. etc.</p> </blockquote> <p>The content of the first file are not in a uniform order so that's why I'm trying it with search ,match and print approach</p> <p>I hope you understand my problem</p> <p>This is what I have tried</p> <pre><code> 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 &gt;&gt;output, match.group(),"\t", print &gt;&gt;output, '%d:%d' % ( s, e),"\n", </code></pre> <p>what my code does is it matches the second product list file with the full content file but gives me just the index of the product_Names not the description and price ..</p> <p>what I want is an index/span from Product_name to price..</p> <p>like from mashed potatoes ---- 9.99$( mashed potatoes - [0:58]),,m just getting [0:14]</p> <p>and also any way to print the description and price using the same approach</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload