in Education by
I am trying to open a zip file and iterate through the PDFs in the zip file. I want to scrape a certain portion of the text in the pdf. I am using the following code: def get_text(part): #Create path path = f'C:\\Users\\user\\Data\\Part_{part}.zip' with zipfile.ZipFile(path) as data: listdata = data.namelist() onlypdfs = [k for k in listdata if '_2018' in k or '_2019' in k or '_2020' in k or '_2021' in k or '_2022' in k] for file in onlypdfs: with data.open(file, "r") as f: #Get the pdf pdffile = pdftotext.PDF(f) text = ("\n\n".join(pdffile)) #Remove the newline characters text = text.replace('\r\n', ' ') text = text.replace('\r', ' ') text = text.replace('\n', ' ') text = text.replace('\x0c', ' ') #Get the text that will talk about what I want try: text2 = re.findall(r'FEES (.+?) Types', text, re.IGNORECASE)[-1] except: text2 = 'PROBLEM' #Return the file name and the text return file, text2 Then in the next line I am running: info = [] for i in range(1,2): info.append(get_text(i)) info My output is only the first file and text. I have 4 PDFs in the zip folder. Ideally, I want it to iterate through the 30+ zip files. But I am having trouble with just one. I've seen this question asked before, but the solutions didn't fit my problem. Is it something with the with statement? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You need to process all the files and store each of them as you iterate. An example of how you could do this is to store them in a list of tuples: file_list = [] for file in onlypdfs: ... file_list.append((file, text2) return file_list You could then use this like so: info = [] for i in range(1,2): list = get_text(i) for file_text in list: info.append(file_text) print(info)

Related questions

0 votes
    There are record-once versions of the compact disk and digital video disk, which can be written only once ... Media in portion Storage and File Structures of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    With reference to satellite communication, the anti-jamming technique preferred is select one: a. Key leverage ... spectrum modulation Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    The relation EMPDT1 is defined with attributes empcode(unique), name, street, city, state, and pincode. ... topic in division Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I have created an app which I used the JSQMessageViewController and it works fine in iOS 8. I used ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Find the probability of getting a head when a coin is tossed once. Also, find the probability of getting a tail. Select the correct answer from above options...
asked Nov 19, 2021 in Education by JackTerrance
0 votes
0 votes
    The value of the control variables can be decreased in the For …..Next loop with the help of the ___ statement in looping statement Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    I have minified all my js files using require, but require created a minified js file( main.min.js ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have minified all my js files using require, but require created a minified js file( main.min.js ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I have an object that I want to move by swipe, for example when the swipe is up the object ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am connecting to server using NSURLConnection. The server asks for basic authentication for which I am ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    The handler runs only once even if you run the Playbook many times. (1)True (2)False...
asked Jul 5, 2021 in Education by JackTerrance
0 votes
    In NoSQL databases, the data can be stored ___________. (1)Multiple times (2)Only once...
asked Apr 21, 2021 in Technology by JackTerrance
0 votes
    In which search problem, to find the shortest path, each city must be visited once only? Map coloring ... path between a source and a destination Travelling Salesman problem...
asked Mar 8, 2021 in Technology by JackTerrance
0 votes
    How does dispatch_once manages to run only once?...
asked Nov 10, 2020 in Technology by JackTerrance
...