"Espen S. Frederiksen" wrote:
The problem occur when I try to split up the function as shown below. I would like to store the data list, update it if nessesary and return it when appropriate. Am I making it unessesary complex when I use the class? Is there maybe a way to declare the data list global within the module? Or is there another, possibly different, way to do this?
Take out all the "import __main__" statements and you should be fine. Python lets you access two namespaces at once: the "local" namespace and the "global" namespace. Were it not for the global namespace, you would need to do something like "import __main__". But since globals are there, everything available at the module level is also available at the function level. Shane
class Testclass: def setdata(self,val1,val2,val3): self.data = [val1,val2,val3] def updatedata(self, index): self.data[index] = self.data[index]+1 def display(self): return self.data
x = Testclass()
def createdata(var1, var2, var3): import __main__ x.setdata(var1, var2, var3)
def update(index): import __main__ x.updatedata(index)
def returndata(): import __main__ return x.display()