Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何分配;IDs";定义中的全局变量_Python_Variables_Global Variables - Fatal编程技术网

Python 如何分配;IDs";定义中的全局变量

Python 如何分配;IDs";定义中的全局变量,python,variables,global-variables,Python,Variables,Global Variables,好的,我有一个函数,它基本上是一个分组的全局变量,这些变量会被其他定义更新 我想做的是能够在以后重新使用这个定义将CTRL添加到其他布局中,但是我遇到了使用相同变量名的问题。有没有办法为每个变量添加属性?或者python中的ID,以便在第二次运行函数时,变量具有标识符 def createDomeLightCTRLS(self,lightName,parentFrame): lightShape = mel.listRelatives(lightName,shapes=True)

好的,我有一个函数,它基本上是一个分组的全局变量,这些变量会被其他定义更新

我想做的是能够在以后重新使用这个定义将CTRL添加到其他布局中,但是我遇到了使用相同变量名的问题。有没有办法为每个变量添加属性?或者python中的ID,以便在第二次运行函数时,变量具有标识符

def createDomeLightCTRLS(self,lightName,parentFrame):

    lightShape = mel.listRelatives(lightName,shapes=True)   

    self.LD3 = mel.rowLayout(parent = parentFrame, numberOfColumns = 7, cat = [(1,'left',10)])

    self.LD3_Spherical = mel.checkBox(str(lightName[0]) + '_spherical', label = 'Dome Spherical' , value = False )     
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                
    self.LD3_SubDivs = mel.intSliderGrp(str(lightName[0]) + '_subdivs', label = 'SubDivs', min = 1, max = 100, field = True, value = 8, cw = [(1,45),(2,45),(3,75)])
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                        
    self.LD3_rayDistCheck = mel.checkBox(str(lightName[0]) + '_rayDistCheck', label = 'Use Distance', value = False)             
    mel.separator(hr = False, width = 10, height = 20, style = 'out')          
    self.LD3_rayDist = mel.floatSliderGrp(str(lightName[0]) + '_rayDist', label = 'Distance', pre = 3, enable = False, field = True, value = False, min = 1, max = 1000000000, cw = [(1,45),(2,85),(3,85)] )

    mel.setParent('..') # LD3 ( LD3 rowLayout) CLOSED

    self.LD4 = mel.rowLayout(parent = parentFrame, numberOfColumns = 7, cat = [(1,'left',10)])

    self.LD4_shadowBias = mel.floatFieldGrp( annotation = "Dome Light Light Shadow Bias: Distance of Shadows from Objects, (Default Should Be Enough)", label = 'Shadow Bias', numberOfFields = 1, precision = 3, value1 = .020, columnWidth = [(1,65),(2,75)], enable = True)
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                
    self.LD4_shadowColor = mel.colorSliderGrp( annotation = "Dome Light Shadow Color", label='Shadow Color', columnWidth = [( 1,75 ),( 2,75 ),( 3,115 )], rgb=( 0, 0, 0 ), enable = True)               

    mel.setParent('..') # LD4 ( LD4 rowLayout) CLOSED

    self.LD5 = mel.rowLayout(parent = parentFrame, numberOfColumns = 5, columnAttach=[(1,'left',10)])        

    self.LD5_UseHDRI = mel.checkBox(str(lightName[0]) + '_useHDRI', annotation = "On/Off Use Dome Texture, Overrides Dome Light Color", label='Use HDRI', v=False)        
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                
    self.LD5_TexAdaptive = mel.checkBox(str(lightName[0]) + '_texAdaptive', annotation = "On/Off Explict Texture Resoltion, Overrides input File Resolution", label='Texture Adaptive', enable = False, v=False)        
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                
    self.LD5_TexRes = mel.floatSliderGrp(str(lightName[0]) + '_texRes', annotation = "Texture Resolution, if Texture Adaptive is Enabled", 
                                         columnAttach = [(2,'both',5)], 
                                         columnWidth = [(1,95),(2,75),(3,125)], 
                                         enable = False, 
                                         label='Texture Resolution', 
                                         field=True, 
                                         minValue=128, 
                                         maxValue=4096, 
                                         step = 128, 
                                         fieldMinValue=128, 
                                         fieldMaxValue=4096, 
                                         value=128
                                         )

    mel.setParent('..') # LD5 ( LD5 rowLayout) CLOSED

    self.LD6 = mel.rowLayout(parent = parentFrame, numberOfColumns = 4, columnWidth=[(1,300)],columnAttach=[(1,'both',10)])  

    self.LD6_UseRGB = mel.checkBox(str(lightName[0]) + '_useRGB', annotation = "Use Color Slider to Determine Dome Light Color", label='Use RGB Dome Color', enable = False, v=False)
    self.LD6_UseHDRIFile = mel.checkBox (str(lightName[0]) + '_useHDRIFile', annotation = "Use HDRI to Determine Dome Light Color", label='Use HDRI File', enable = False, v=False)

    mel.setParent('..') # LD6 (LD6 rowLayout) CLOSED 

    self.LD7 = mel.rowLayout(parent = parentFrame, 
    numberOfColumns = 4,
    columnWidth=[(1,300)],
    columnAttach=[(1,'both',10),(2,'both',0),(3,'both',5),(4,'both',5)])

    self.LD7_DomeColor = mel.colorSliderGrp(str(lightName[0]) + '_domeColor', annotation = "Dome Light Color", 
                                                  label='Dome Color', 
                                                  enable = False, 
                                                  columnAttach = [(1,'both',0), (2,'both',5), (3,'left',0), (4,'both',0)], 
                                                  columnWidth = [( 1,55 ),( 2,60 ),( 3,10 ),(4,0)], 
                                                  rgb=( 1, 1, 1 )
                                                  )

    self.LD7_HDRITextName = mel.text(str(lightName[0]) + '_HDRITextName', annotation = "Search for HDRI (jpg,HDR) to Use in Dome Light", label = 'HDRI File Name', enable = False)
    self.LD7_HDRITextField = mel.textField(str(lightName[0]) + '_HDRITextField', text = '', width = 150, enable = False )
    self.LD7_HDRIButton = mel.symbolButton (str(lightName[0]) + '_HDRISymbolButton', image='openScript.png',enable = False)

    mel.setParent('..') # (LD7 (LD7 rowLayout) CLOSE                       

    #options

    self.LD8_optionFrame = mel.frameLayout(str(lightName[0]) + '_optionFrame',parent = parentFrame, label = 'Options', labelVisible = True, cl = True, cll = True )

    self.LD8 = mel.rowLayout(parent = self.LD8_optionFrame,numberOfColumns = 9, cat = [(1,'left',10)])

    self.LD8_invisible = mel.checkBox(str(lightName[0]) + '_invisible',label = 'Invisible', value = False)         
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                        
    self.LD8_irradianceMap = mel.checkBox(str(lightName[0]) + '_storeIrradiance',label = 'Store with Irradiance', value = False)
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                                
    self.LD8_diffuse = mel.checkBox(str(lightName[0]) + '_diffuse',label = 'Diffuse', value = True)
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                
    self.LD8_specular = mel.checkBox(str(lightName[0]) + '_specular',label = 'Specular', value = True)
    mel.separator(hr = False, width = 10, height = 20, style = 'out')                                
    self.LD8_reflection = mel.checkBox(str(lightName[0]) + '_reflection',label = 'Reflection', value = True)

    mel.setParent('..') # (LD8 (LD8 rowLayout) CLOSE

    mel.setParent('..') # LR8_optionFrame (LR8_optionFrame frameLayout) CLOSED
非常感谢你!
让我知道是否有更简单或更好的方法来实现这一点,因为我对python绝对是新手

编辑:此代码不起作用。我会删除它,除非我认为它有助于指出提问者的问题

应该在解释器中测试它

您可以在python中向任何对象“添加变量”

a = range(10)
a.ID = 'MY ID'

我不太清楚你在问什么

我不太明白你在问什么。代码中唯一的“全局”变量是
mel
,我猜它是一个模块,而不是您所说的。如果你想给你的
LDx\u成员变量附加一些额外的数据,也许你应该使用一些其他的数据结构(比如嵌套列表或字典),而不是给它们唯一的变量名。不要得到提示。而且:
如果实现很难解释,那么这是一个坏主意。
阅读python风格指南。阅读一些像样的编码标准,例如,也应该是有益的。这不适用于任何对象,只适用于某些类型。许多内置类型(如
列表
dict
元组
,以及各种数字类型)不允许您设置任意属性
[].foo=“bar”
=>
属性错误:“list”对象没有属性“foo”
。默认情况下,自定义类确实允许这样做(尽管您可以通过为它们提供一个不带
\uu dict\uuu
\uu slots\uuu
类变量来防止这样做)。您的示例是一个无法工作的情况(在Python2或Python3中)。