I am working on a little “plugin” for a software, I am trying to put in application all the python I learnt here.
I have some issues with the “programmatically generation” of an instance of my class:
index = 0 naming = ["node_plugin_"+ str(index) for i in range(100)] start_call = False def start(): #This function is launch when the user select the name of the plugin in the pull down menu. #A popup will appears and ask to the user some variables global start_call start_call = True #user input with popup var01 = "/my/path/my/file" var02 = "Cycle" var03 = "Additive" class Plugin: def __init__(self, var01, var02, var03, index): self.var01 = var01 self.var02 = var02 self.var03 = var03 self.index = index def my_function(self): print(self.var01) instance_Plugin = Plugin(var01, var02, var03, index) return instance_Plugin, start_call #To check if the user call the plugin if start_call == True: naming[index], start_call = start() print(start_call) >>>False start() print(start_call) >>>>True a = naming[index].var02 print(a) >>> AttributeError: 'str' object has no attribute 'var02' print(naming[index].my_function()) >>>AttributeError: 'str' object has no attribute 'my_function'
naming[index] should be associated with the return value of start(), in this case instance_Plugin, no?
To summarise, I don’t know how to associate a variable in the global scope to an instance class generated in a function.