Maya 2012 中的 Python help() 表现得很奇怪

发布于 2024-12-12 02:19:45 字数 1173 浏览 0 评论 0原文

这似乎与代码的内容完全无关,所以我将保持它的通用性。

我在一个模块底部的最后一个类中添加了一个多行文档字符串 - 只是向事物添加标签 - 当我通过 Maya 的脚本编辑器导入模块并在该类上运行 help(module.Class) 时,我收到此错误:

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

我花了一段时间来缩小导致错误的多行字符串的范围,将其缩减为使用 1 或 2 行,但超出了范围就失败了。我尝试将大型多行注释移至另一个类并对此提供帮助,并且效果很好,因此看来注释没有问题。然后我对模块中新的最后一个类进行了帮助,但失败了。看来接近尾声的位置才是问题所在。

我将注释移回到失败的类,并删除了它的所有代码并执行了 help(),它工作得很好。我开始重新添加方法,它一直工作到最后一个,其中只有一行代码。我改变了它的每一部分 - 重命名它,删除参数,将其一行代码交换为通行证 - 对类的帮助总是失败,直到我彻底删除它。 Help 确实对 module.Class.method 起作用,因此该方法本身及其大的多行注释似乎没问题。

然后,我将模块文件中的整个类移至其之前的类之前。现在帮助就可以了。但是,现在文件中最后一个类的帮助失败了,尽管它甚至没有文档字符串。我把班级移回最底层,开始摆弄最后的东西。最后一种方法似乎有问题,这意味着即使我删除了之前的许多文本(比仅删除最后的文本更多的文本),我仍然会遇到问题。我在最后一个方法中添加了一个文档字符串,但帮助失败了,但是在最后三个方法中添加了一个文档字符串(只是一个“任何”),使其再次起作用。这整件事真是令人费解。

这是一个我不知何故错过的已知问题吗?似乎某些类/方法配置可能会杀死帮助,除非所有方法(尤其是稍微复杂的方法)都有文档字符串。

编辑以添加一小段代码作为示例:

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

这是文件中最终类的最终方法。它导致帮助崩溃。删除此方法将允许帮助再次在该类上工作。然而,保留这个并将类本身移到前一个类之上将导致该类再次正常工作,但随后在文件中的新最终类上开始失败。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空气里的味道 2024-12-19 02:19:45

当您导入maya模块时,请说

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

确保您必须在每次导入的末尾放置为cmd或mel部分

然后您使用让我们说

cmds.sphere()

maya还定义了自己的帮助函数! help()

否则你最终会混合/覆盖 Maya 定义的一些方法而不是 python 的方法,这也可能是你得到奇怪结果的原因。

我认为如果将类移到模块中的任何位置不会产生任何影响,因为当实例化对象时,它与其在 OO 代码中的位置无关......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文