Forum: Poser Python Scripting


Subject: Dumb question of the day list unpacking

grichter opened this issue on Feb 03, 2011 · 5 posts


grichter posted Thu, 03 February 2011 at 12:57 AM

Semi rookie

But

InColorValue = [0.607843, 0.686275, 0.811765]

and print InColorValue returns

0.607843
0.686275
0.811765

to unpack the list I have tried several methods I have found on the net which lead me to believe this should work.

r1, g1, b1 = InColorValue

But based on all the various ways I have found on the net about unpacking tupols or lists I keep getting the following TypeError: unpack non-sequence

So I am doing something very basic wrong. What is it?

I want to feed the values into a material node using a .SetColor(r1,g1,b1)

Thanks in advance for any tips or suggestions

Gary

"Those who lose themselves in a passion lose less than those who lose their passion"


markschum posted Thu, 03 February 2011 at 1:07 PM

use an index

print  len(incolorvalue)

r = incolorvalue[1]

g = incolorvalue[2]

b = incolorvalue[3]

I dont remember offhand if the index starts at 1 or 0 but should be easy to check

www.python.org and get the manuals


adp001 posted Thu, 03 February 2011 at 1:50 PM

Because Poser Python is somewhat outdated (even with P8), try this:

<pre style="font-family:'courier new', courier;">

ar=[1.234, 2.345, 3.456] >>> ar [1.234, 2.3450000000000002, 3.456]

a,b,c=tuple(ar) >>> a 1.234 >>> b 2.3450000000000002 >>> c 3.456




markschum posted Thu, 03 February 2011 at 4:02 PM

thats a nicer method , noted , thanks .


grichter posted Sun, 06 February 2011 at 11:51 AM

Found my problem using what I assumed would work.  Based on conditions I import various other scripts and had a typo, that for the life of me I couldn't see. So the original problem is mute. But you examples make things even easier when I want to pick one out of the list or tuple.

Thanks a million

Gary

"Those who lose themselves in a passion lose less than those who lose their passion"