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 ] # 

5
  • You must change the string to numbers. Is this a python related question? because you could add Python as a tag too. Commented Mar 21, 2013 at 0:10
  • Thanks for the quick response Zaf. I have no idea how to do that. Is my approach the correct way? Commented Mar 21, 2013 at 0:15
  • solved it using cmds.curve( p = eval( pStr ) ) Commented Mar 21, 2013 at 0:18
  • 2
    @WarrenDaza, eval is generally frowned upon. Commented Mar 21, 2013 at 0:19
  • There was another question similar here on stack overflow stackoverflow.com/questions/379906/… maybe that help you Commented Mar 21, 2013 at 0:22

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

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)]

2 Comments

Heh, this might be too clever :P Also, what's with the 1:?
@askewchan, I used a program called dreampie as my python shell, and it puts those number in there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.