简体   繁体   中英

Python's help() in Maya 2012 acting quite strange

This seems completely unrelated to the contents of the code, so I'll keep it generic.

I was adding a multiline docstring to the last class at the bottom of one of my modules - just something that adds labels to things - and when I imported the module via Maya's script editor and ran a help(module.Class) on that class, I received this error:

# Error: IndexError: file C:\Program Files\Autodesk\Maya2012\bin\python26.zip\inspect.py line 568: list index out of range # 

I spent awhile narrowing down what about the multiline string was causing the error, paring it down to working with 1 or 2 lines, but failing beyond that. I tried moving the large, multiline comment to another class and doing a help on that, and it worked fine, so it seemed the comment was not at issue. I then did a help on the new last class in the module, and it failed. It seemed like position near the end was the issue.

I moved the comment back to the failing class and removed all of its code and did a help(), and it worked fine. I started adding back in methods, and it worked all the way up until the last one, which had only one line of code in it. I changed every part of it - renamed it, removed args, swapped its one line of code for a pass - help for the class always failed until I removed it outright. Help did work on the module.Class.method, so the method itself, and its big, multiline comment seemed okay.

I then moved the entire class up in the module file to before the class right before it. Help now worked for it. However, now help failed for the last class in the file, though it doesn't even have a docstring. I moved the class back to the bottom, and started playing with the things at the end of it. It seemed to have a problem with the last method, meaning even if I deleted many before them - more text than deleting just the one at the end - I'd still get a problem. I added a docstring to the last method and help failed, but adding a docstring (just a "whatever") to the last three made it work again. This whole thing is completely baffling.

Is this a known issue that I've somehow missed? It seems like some class/method configurations can kill help unless all methods - especially the more than lightly complicated ones - have docstrings.

editing to add a small bit of code as an example:

def setLabelChangeDGC (self, control):
    control.dragCallback = self.getLabelChangeDGC(control)

That was the final method of the final class in the file. It caused help to crash. Removing this method would allow help to work on the class again. However, leaving this in and moving the class itself above the previous class would cause it to work fine again for this class, but then begin to fail on the new final class in the file.

when you import maya modules say

import maya.cmds as cmds # or
import maya.mel as mel

make sure you must put as cmds or as mel part at the end of each import

then you use lets say

cmds.sphere()

maya also defines its own help function!!! help()

otherwise you will end up mixing/overriding some of the methods defined by maya over python's, this could also be the reason why you getting the strange result .

I do not think if you move your class anywhere up in the module will make any difference because when an object is instantiated it is irrelevant of its placement in the OO code...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM