I was looking for some corner cases for loading python files (2.7 on osx) as configuration files. I wanted to see what this behavior is if I looped through execfile. I was expecting a memory error or a big replacement, but I was pretty surprised when I got a different result.
I install the test script as follows:
'd' python script with:
x = 0
execfile("d1")
'd1' python script with:
x += 1
print "x = %d" % x
execfile("d2")
'd2' python script with:
x += 1
print "x = %d" % x
execfile("d1")
Result:
$ ./d
x = 1
x = 2
x = 3
... removed for brevity ...
x = 997
x = 998
x = 999
Traceback (most recent call last):
File "./d", line 5, in <module>
execfile("d1")
File "d1", line 5, in <module>
execfile("d2")
File "d2", line 5, in <module>
execfile("d1")
... removed for brevity ...
File "d1", line 5, in <module>
execfile("d2")
File "d2", line 5, in <module>
execfile("d1")
File "d1", line 5, in <module>
execfile("d2")
KeyError: 'unknown symbol table entry'
I was just curious if there was anyone who could explain what was going on here? Why does it stop after execfile ~ 1000 times?
source
share