2

I have a list of floats [234, 533, 734, 964, 623, 744, 244, 353, 264]. Then, I format it to a string like "(234, 533, 734), (964, 623, 744), (244, 353, 264)".

This is a format example of the function I'm passing it to:

cmds.curve( p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9)] )

Here's what I used that returned an error:

cmds.curve( p = [ pStr ] )

Here's the error:

Line 142: Invalid arguments for flag 'p'.  Expected ( distance, distance, distance ), got [ str, str ] # 

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
Warren Daza
  • 41
  • 1
  • 5

2 Answers2

1

Try this and see if it works for you. I have a feeling that you are converting to a string unnecessarily.

floats = [234, 533, 734, 964, 623, 744, 244, 353, 264]
groups = [tuple(floats[i:i+3]) for i in range(0, len(floats), 3] 
cmds.curve(p=groups)
sberry
  • 128,281
  • 18
  • 138
  • 165
1

Try using zip, click here for the python docs.

>>> my_list = [234, 533, 734, 964, 623, 744, 244, 353, 264]
>>> zip(*[iter(my_list)]*3)
[(234, 533, 734), (964, 623, 744), (244, 353, 264)]
Community
  • 1
  • 1
John
  • 13,197
  • 7
  • 51
  • 101
  • Heh, this might be too clever :P Also, what's with the `1:`? – askewchan Mar 21 '13 at 03:28
  • @askewchan, I used a program called [dreampie](http://www.dreampie.org/) as my python shell, and it puts those number in there. – John Mar 21 '13 at 10:49