|
-
November 17th, 2011, 03:10 AM
#2
Hmmm almost 60 views and no replies .... good, I can take all the credit for finally figuring it out myself.
I really had to get this off of my chest - because it feels soooo F#$% - ing good. Many hours, many posts, much frustration, many times almost giving up - I finally got this high score list to work properly. And it was such a simple thing.... I had a function to create the name list and one to create the score list, then for some stupid reason I re-created each list in the function to store the high score list. I even got to have a bit of fun with nesting try/except/else blocks .. oh joy!!
heres the finished function product, if anyone cares:
Code:
def store_scores(name_list, score_list):
try:
f = open("pScores.dat", "rb")
except IOError:
f = open("pScores.dat", "wb")
pickle.dump(name_list, f)
pickle.dump(score_list, f)
else:
try:
y = pickle.load(f)
z = pickle.load(f)
except EOFError:
f.close()
f = open("pScores.dat", "wb")
pickle.dump(name_list, f)
pickle.dump(score_list, f)
else:
f.close
f = open("pScores.dat", "wb")
name_list.extend(y)
score_list.extend(z)
pickle.dump(name_list, f)
pickle.dump(score_list, f)
f.close()
Im sure there's a way to neaten this up a bit, if anyone has any suggestions on that I'm game. But for right now Im a real happy Python newb
I even got the formatting to work right in the print function. I have only to sort the list high -> low and make it so it only shows the top 5. I already have in my head how to do this, and its not a complex thing.
My only concern is that there is alot of opening and closing of files in this function (above). I'm going to experiment with different access modes .... tomorrow. Im enjoying a victory right now :P

*HICCUP*
"In most gardens they make the beds too soft - so that the flowers are always asleep" - Tiger Lily
Similar Threads
-
By HTRegz in forum General Computer Discussions
Replies: 0
Last Post: September 19th, 2006, 07:28 PM
-
By HTRegz in forum Other Tutorials Forum
Replies: 20
Last Post: September 10th, 2005, 07:28 AM
-
By PacketThirst in forum Other Tutorials Forum
Replies: 2
Last Post: August 14th, 2005, 07:16 PM
-
By [pHA]XeNoCiDe in forum AntiOnline's General Chit Chat
Replies: 11
Last Post: July 8th, 2002, 07:56 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|