Hi thanks for your reply.
When I say "at some point in the future" I mean seconds. In short, let me give you an example.
For example I have one script that is connected through a socket and it responds to events received from that socket (the program runs until it receives a specific event from the socket).
-data may change through some of the events
-script periodically saves data every minute or so
-It seems that when i set off that "end/exit" event, and the whole script reaches its last sys.exit() the file reverts within
The module for loading and saving the data is pretty simple:
#loads data and returns:
# a dictionary of people
# with each person being a dict. with 3 components: name(string), numbersSet1(number list), numbersSet2(number list)
# with each numberset being a list of 8 numbers Ex: numbersSet1 is [1,2,3,4,5,6,7,8]
def loadData(filename):
i = 0;
people = {}
f = open(filename,'r')
for line in f.readlines():
if(i%3 == 0): #name
name = line.strip()
elif(i%3 == 1): #first set of numbers
parts = line.partition('-')
numbersSet1 = map(int, parts[2].split(':') )
else: #second set of numbers
parts = line.partition('-')
numbersSet2 = map(int, parts[2].split(':') )
#now we consolidate elements into a "person structure"
people[name] = {'name':name, 'numbersSet1':numbersSet1, 'numbersSet2':numbersSet2}
i = i+1
f.close()
print "Loaded Data..."
return people
#saves into file with following format:
#Joe
# numbersSet1-1:2:3:4:5:6:7:8
# numbersSet2-1:2:3:4:5:6:7:8
#Charles
# numbersSet1-1:2:3:4:5:6:7:8
# numbersSet2-1:2:3:4:5:6:7:8
#Bob
# numbersSet1-1:2:3:4:5:6:7:8
# numbersSet2-1:2:3:4:5:6:7:8
# ...and so on...
def saveData(filename,people):
f = open(filename,'w')
for key in people.keys():
person = people[key]
f.write(person['name'])
f.write('\n\tnumbersSet1-')
numbersSet1 = person['numbersSet1']
f.write(str(numbersSet1[0]))
for i in range(1,8):
f.write(':')
f.write(str(numbersSet1[i]))
f.write('\n\tnumbersSet2-')
numbersSet2 = person['numbersSet2']
f.write(str(numbersSet2[0]))
for i in range(1,8):
f.write(':')
f.write(str(numbersSet2[i]))
f.write('\n')
f.close()
return
Where you would make calls such as
and
(Note: loadData only called once at the beginning of script)
(Also, no exceptions or errors have ever been raised)