-1
r, g, b, *a = img_list[generated_number]

What does this means in python3? I'm porting the stegano library to python 2 (since burgled-batteries has trouble with libraries in python3 while importing from sbcl).

Is there a way of converting this notation to python 2 notation (like how type annotation can be overcome with import typing and x.__annotations__ = {})? More generally, what is this supposed to signify? Since it raises a syntax error when run on python 2.

Thanks!

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
kawakaze
  • 96
  • 1
  • 8

1 Answers1

1

It's an iterable unpacking assignment with a catch-all component; the first 3 values are assigned to r, g and b respectively, the remainder of the values are assigned as a sequence to *a (catching any values beyond the first 3).

To achieve the same in Python 2, you'll need to use slicing:

(r, g, b), a = img_list[generated_number][:3], img_list[generated_number][3:]

See PEP 3132 -- Extended Iterable Unpacking for details on the new feature.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thank you very much! I'll accept the answer in 5 minutes. Sorry for the (as it turns out) fairly stupid question. – kawakaze Jun 24 '17 at 16:27