Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103333

avoid for loop calling Generator function

Newsgroups comp.lang.python
Date 2016-02-22 03:15 -0800
Message-ID <e5e4a934-4eeb-46ed-892f-cda9e903c1cd@googlegroups.com> (permalink)
Subject avoid for loop calling Generator function
From Arshpreet Singh <arsh840@gmail.com>

Show all headers | View raw


Hi, I am converting PDF into text file, I am using following code.

from pypdf2 import PdfFileReader 

def read_pdf(pdfFileName):
	
    pdf = PdfFileReader(pdfFileName) 

    yield from (pg.extractText() for pg in pdf.pages)

for i in read_pdf('book.pdf'):
     print(i)

I want to avoid for loop , I also tried to create another function and call read_pdf() inside that new function using yield from but I think I am missing real picture here 

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

avoid for loop calling Generator function Arshpreet Singh <arsh840@gmail.com> - 2016-02-22 03:15 -0800
  Re: avoid for loop calling Generator function Peter Otten <__peter__@web.de> - 2016-02-22 14:34 +0100
    Re: avoid for loop calling Generator function Arshpreet Singh <arsh840@gmail.com> - 2016-02-22 07:38 -0800
      Re: avoid for loop calling Generator function Chris Angelico <rosuav@gmail.com> - 2016-02-23 02:46 +1100
      Re: avoid for loop calling Generator function Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-22 09:11 -0700

csiph-web