1

I am little bit new to Python and I got stuck a bit in this moment:

c = 5
cmds.pointPosition(geo[0]+".cv[0]["+c+"2]", w=True)

it gives me error:

Error: TypeError: file line 39: coercing to Unicode: need string or buffer, int found #

Question is how to put variable c = 5 inside second bracket so it will be 7?

1
  • Try str(c) or format() or an f-string. Commented Jan 21, 2018 at 4:18

3 Answers 3

6

Avoid string concatenation when you can. This is a good use case for str.format.

cmds.pointPosition("{}.cv[0][{}]".format(geo[0], c + 2), w=True)

Which works assuming c holds the value of an integer to begin with (otherwise, the c + 2 step fails).

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome explanation . Thanks :)
4

Python does not automatically convert an integer into its string representation like some languages. You need convert it explicitly yourself with str(), format(), or an f-string.

Comments

1
c = 5
cmds.pointPosition(geo[0]+".cv[0][" + str(c) + "2]", w=True)

In Python, you can't concatenate str and int.

Comments

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.