如何从导入模块中获取变量

时间:2015-03-06 05:06:40

标签: python

我正在尝试获取变量 - clipFileInfo,它来自导入模块。我运行以下代码:

from Library import libmaya
publishClip = libmaya.ClipPublish()
clip = publishClip.getClip()

print clip.clipFileInfo

但它会给我一个错误,说明# AttributeError: 'list' object has no attribute 'clipFileInfo' #

这是我从

派生的代码部分
class ClipPublish( lib.ClipPublish ):
    ...
    ...

    def __getclipFileInfo( self ):
        '''
        Return list of dicts to pass through to writeClip function
        '''
        clipFileInfo = []
        for rig in self.rigList.Rigs():
            actor = rig.pop( 'actor', None )
            if actor:
                clipFileInfo = {}
                clipFileInfo['actor'] = actor
                clipFileInfo['rig'] = rig
                clipFileInfo['name'] = self.__unit.get( rig['name'] )
                clipFileInfo.append( clipFileInfo )               
        return clipFileInfo

    def getClip( self ):
        clipFileInfo = self.__getclipFileInfo()
        if clipFileInfo:
            start = self.frameRange.startFrame()
            end = self.frameRange.endFrame()
            clipFile = writeC.writeclip( clipFileInfo, start, end )
            if clipFile == None:
                return None
            return clipFile[0] if self.isSingle() else clipFile
        return []

首先可以这样做吗?

1 个答案:

答案 0 :(得分:2)

看起来你正试图从函数中拉出一个局部变量。除非函数返回此局部变量,否则无法实现。

相反,正如评论所说,你应该调用publishClip.__getclipFileInfo()来获取该变量的值,因为该函数 返回它。

为了更明确,请尝试以下代码。

from Library import libmaya
publishClip = libmaya.ClipPublish()
info = publishClip.__getclipFileInfo()

print info