Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do I tell a script to compare a string with the names of all materials? This following code does not work:
for i in len(bpy.data.materials):
if str(color) == bpy.data.materials[i].name:
mat = bpy.data.materials[i]
mesh.materials.append(mat)
break
Error:
TypeError: 'int' object is not iterable (line 1)
Thanks.
That first line needs to be changed to for i in range(len(bpy.data.materials)):.
Alternatively, you could write the following instead:
for mat in bpy.data.materials:
if str(color) == mat.name:
mesh.materials.append(mat)
break
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How can I find a string in a text file and then print which line that string was found on?
I am using Python 2.7.
In Python, enumerate is handy for this sort of thing:
with open(myfile) as f:
for index, line in enumerate(f, 1):
if s in line:
print("'{0}' found on line {1}".format(s, index))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
the expected output of this code is [x**2,x+2] but when i try to run it the system gives me an error saying that the variable 'x' is not defined.how to fix this issue. I would like to get the map the expression to a graph.
l=[1,2]
out=[]
for i in l:
if i==1:
y=x**2
out.append(y)
if i==2:
y=x+2
out.append(y)
print(out)
At y=x**2 you have used the variable x but you have not defined it, which is causing the error. I'm assuming you want it as a string, so just do y="x**2".
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
eg-In this instead of using 21 (a value), I want to use a variable to generalize it
print("{:-^21}".format(".|."*(2*(i+1)-1)))
I want to use something like this
print("{:-^M}".format(".|."*(2*(i+1)-1)))
That can easily enough be done. For example:
M = 40
i = 3
print("{val:-^{width}}".format(width=M, val=".|."*(2*(i+1)-1)))
Outputs:
---------.|..|..|..|..|..|..|.----------
You could also do it with f-strings (note the outer ' because " is used on the inner expression):
print(f'{".|."*(2*(i+1)-1):-^{M}}')
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to convert a tuple:
('Cobra',)
to a string, which when printed yields:
Cobra
#Assuming you have a list of tuples
sample = [('cobra',),('Cat',),('Dog',),('hello',),('Cobra',)]
#For each tuple in the list, Get the first element of each tuple
x = [i[0] for i in sample]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can some one suggest equivalent code in python for below line
UInt32.Parse(("000000" + hexfileln.Substring(1, 2)), NumberStyles.HexNumber);
It is pointless to prefix a hex number with zeros. Ignoring that, and noting that the int constructor accepts a string argument and the base, you can use int to parse a hexadecimal number:
int(hexfileln[1:3], 16)