Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Loop is giving an error

Loop is giving an error

Anonymous
Not applicable
803 Views
6 Replies
Message 1 of 7

Loop is giving an error

Anonymous
Not applicable

Why am i getting an error that says # Error: TypeError: file <maya console> line 46: 'int' object is not callable # . 

 

leng = len(jointarr) 

for i in range(leng):
    if i == 0:
       print("True")
    else:
       print("False") 
         
    
0 Likes
804 Views
6 Replies
Replies (6)
Message 2 of 7

mspeer
Consultant
Consultant

Hi!

Your script is missing important information:

 

1. There is no line 46

2. What is jointarr?

If i set jointarr to any string value the script works fine here.

0 Likes
Message 3 of 7

Anonymous
Not applicable

there is line 46 it just a piece of the code, the snippet i put line 46 is where the for loop starts. jointarr is an array and it gvies back 3 or 2 depends on how many joints i selected so im just check the lenght of the array with len.

0 Likes
Message 4 of 7

Anonymous
Not applicable

Just tried and it works something is up with range function for the loop i even used it on a different script panel and same error.

for i in jointarr:
     if i == 1:
        print("True")
     else:
        print("False")
0 Likes
Message 5 of 7

mspeer
Consultant
Consultant

Hi!

 

Without a complete example the problem can't be detected.

Here this code works fine, when i define a valid value for jointarr.

0 Likes
Message 6 of 7

Anonymous
Not applicable

Yup got it working all i did was just close maya and reopened it.

0 Likes
Message 7 of 7

RFlannery1
Collaborator
Collaborator

My best guess is that at some point you made a variable named either "len" or "range".  This overrode the Python built-in function of the same name.  For example, the following code would generate a similar error:

len = 5
myList = ['aa', 'bb', 'cc']
print(len(myList))

When this happens, restarting Maya is the correct fix because the Python interpreter has to be restarted.  The main takeaway here: Don't use Python keywords as variable names.