'Python remembers variable in memory despite intizialition and variable not in memory

I can't figure this problem out with a variable that does not reset in a function call.

The problem I am facing is that I am having trouble doing something as simple as initializing a variable in a function.

I call a specific function:

d_psd.get(base_folder)

The function input variables are defined like this: def get(self, base_folder, data_all = dict(), ind=0)

At the end of the function, I do this: self.data = data_all self.data= dict(sorted(self.data.items())) del data_all

So each time I run this function, data_all should be set to an empty dictionary. Yet, when I call this function, the result I often (not always) get, is that of a filled data structure of a previus run. So by the time I run the function a second time, it does not reset the dictionary.

This behavior confuses me as data_all should always be set to an empty dictionary. And even though I explicitily remove data_all, the system somehow inplicitly has it stored in memory.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source