Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: cannot unpack non-iterable GetColorImage object

i have following situation:

cratecolor.py: (code stripped to its minimum…)

import ... ...


class GetColorImage:  
    def __init__(self, ia=None):
        self.path = None
        self.img = None
        self.img0 = None
        self.s = None
        self.basetime = 0
        self.count = 0
        self.stride = 32
        self.ia = ia
        self.img_size = 640
        self.auto = True
        self.getImage()

    def getImage(self):
        self.ia.remote_device.node_map.ExposureTime.value = 350
        self.ia.remote_device.node_map.Gain.value = 150
    
        ...
        ...

        print(color, l)        # prints: 1 59.64829339143065

        return color, l

main.py: (code stripped to its minimum)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

...
...

 # code exectued on a qthread:

 def getcolor(self, idin):
    color, lightness = cratecolor.GetColorImage(ia=self.ia) #******
    print(color, lightness)

In the line marked with ***** i get the error message color, lightness = cratecolor.GetColorImage(ia=self.ia) TypeError: cannot unpack non-iterable GetColorImage object but i dont get why.
any help appreciated.

>Solution :

You cannot return values from an __init__ function, so you instead must either:

  1. Call the getImage() method when creating the class
  2. Define an __iter__ method for the class to automatically allow you to assign it to multiple variables.

The second one is probably the better solution. Here is the method you would add to the class for it to work:

def __iter__(self):
    return iter(self.getImage())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading