View Full Version : help(python)

02 February 2011, 09:11 AM
hi, i'm a noob in python and i cannot find a solution on my script.

import maya.cmds as mc

factor =1[0]+".u" + "[0.5]" )[0]+".v" + "[" + factor + "]", add=True )

what i'm trying to do is put the value in the v (which is the factor) of the nurbsplane
and i'm having an error of
# TypeError: coercing to Unicode: need string or buffer, list found #

sorry for the noob question

tnx in advance


02 February 2011, 09:45 AM
in python you can only catenate strings together using +
you have tried to "add" an integer to a string and python doesn't allow this. in python you need to use the % method, which is pretty strange to get your head around to start with but is really very straightforward:

iValue = 1
fValue = 3.14
st = 'adding a string to an int value of: %d and also, PI = %.2f (which is a float!)' % (iValue,fValue)
print st
take a look at the python docs for more details:


02 February 2011, 02:03 AM
tnx nathan!
really, it was a big help...

02 February 2011, 03:36 AM
You can also cast the int/float to a string using str()

02 February 2011, 09:24 AM
Hi nathan,

I've researched and studied on what you have told and wrote some and it worked,
but in this i case i was wondering why i couldn't get my script right.
here's the script and the error message:

self.factor = 1.0
self.factors = self.segmentMid*(self.factor+(i*2.0))[0]+".u" + "[0.5]" )[0]+".v[%f]", add=True ) %(self.factors)

TypeError: Object prefix_part_SRF.v[%f] is invalid #

basically i was hoping to select the .uv of the nurbsPlane object....

sorry for being a noob XD

tnx in advance


02 February 2011, 10:44 AM
check this link:

And do this "[%f]"%(val)

You have to use % operator WITH string not the whole function.

02 February 2011, 04:06 AM
thank you!
it works like a charm!


CGTalk Moderation
02 February 2011, 04:06 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.