I can test whether a string is in a text file with python like the following:
if(pdfname in open(filename).read()):
//do something
But how I can I verify it? I want the matching line show up. Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can print out the relevant lines with the second
forstatement below, which I’ve added to your existing code for illustration:This outputs your current line plus my output for verification:
and, checking that file, that is indeed the line it’s found on.
Note that you can simply use a script as follows to do both jobs in a single loop: