Syntax not understood

ast ast at invalid
Thu Nov 4 07:43:23 EDT 2021


Hello

In this function

def get4(srcpages):
     scale = 0.5
     srcpages = PageMerge() + srcpages
     x_increment, y_increment = (scale * i for i in srcpages.xobj_box[2:])
     for i, page in enumerate(srcpages):
         page.scale(scale)
         page.x = x_increment if i & 1 else 0
         page.y = 0 if i & 2 else y_increment
     return srcpages.render()

found here

https://www.blog.pythonlibrary.org/2018/06/06/creating-and-manipulating-pdfs-with-pdfrw/

I do not understand this line:

x_increment, y_increment = (scale * i for i in srcpages.xobj_box[2:])

(scale * i for i in srcpages.xobj_box[2:]) is a generator, a single
object, it should not be possible to unpack it into 2 variables.

x, y = 1 generates an error
x, y = (i for i in range(10)) too

but not

x_increment, y_increment = (scale * i for i in srcpages.xobj_box[2:])

why ?


More information about the Python-list mailing list