• Caching and Python

 

I'm only learning Python, and wanted to ask did I understand the situation correctly.

I wrote this code:

class SomeClass(): someList = []

   def doSmthWithList(self):
         return self.someList

I already know what's wrong with this - I was thinking that by having "someList = []" right after the class definition, I will get an attribute initializer, but it appears that this is static attribute that has nothing to do with self.someList. I just forgot about that.

But what was very strange is checkio behaivour. Even I made a mistake - when I ran "python mycode.py" locally - it was working perfectly. someList was empty before every run (obviously) and I used SomeClass only once, so it worked. And that is clear.

But when I tried running it on checkio, - it behaved differently. First test was ok, but second was failing each time. My application gave very strange results on it. After debugging my code with "print()" right in checkio, I figured out, that after running first test case, someList didn't get cleared, and had some data from the first run, so that corrupted the second run. The more interesting thing that on the third run it was always clear again. So it cleared only each second run.

Am I correct that checkio behaves somewhat strange and running our script not for every test case, but for every second test case? Or maybe it didn't clear the memory.

Please also let me know if I am wrong about Python behavior here.

4