Re: avoid for loop calling Generator function

2016-02-22 Thread Ian Kelly
On Mon, Feb 22, 2016 at 8:38 AM, Arshpreet Singh wrote: > On Monday, 22 February 2016 19:05:24 UTC+5:30, Peter Otten wrote: >> or the slightly less convoluted >> >> sys.stdout.writelines(map("{}\n".format, read_pdf("book.pdf"))) > > Actually I am using this function in Android App which is being

Re: avoid for loop calling Generator function

2016-02-22 Thread Chris Angelico
On Tue, Feb 23, 2016 at 2:38 AM, Arshpreet Singh wrote: >> next(filter(print, read_pdf("book.pdf")), None) > > Why we are w=using filter here? It's a beautiful hack. It'll filter according to the "print" predicate, which always returns None, and will thus filter everything out. One single call to

Re: avoid for loop calling Generator function

2016-02-22 Thread Arshpreet Singh
On Monday, 22 February 2016 19:05:24 UTC+5:30, Peter Otten wrote: > Arshpreet Singh wrote: > > > Hi, I am converting PDF into text file, I am using following code. > > > > from pypdf2 import PdfFileReader > > > > def read_pdf(pdfFileName): > > > > pdf = PdfFileReader(pdfFileName) > > > >

Re: avoid for loop calling Generator function

2016-02-22 Thread Peter Otten
Arshpreet Singh wrote: > 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'):

avoid for loop calling Generator function

2016-02-22 Thread Arshpreet Singh
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