Created
June 26, 2024 18:24
-
-
Save mshafae/8a861c80cfcda7f4aacf91d02baf34f2 to your computer and use it in GitHub Desktop.
CPSC 386 High score demo in class 2024-06-25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pickle | |
from highscore import HighScore | |
def main(): | |
# 13 23 33 100 345 | |
print('hello world') | |
score_list = [HighScore(13), HighScore(23), HighScore(33), HighScore(100), HighScore(345)] | |
print(score_list) | |
pickle_file = 'high_scores.pckl' | |
with open(pickle_file, 'wb') as file_handle: | |
pickle.dump(score_list, file_handle) | |
if __name__ == '__main__': | |
main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pickle | |
from highscore import HighScore | |
def main(): | |
# 13 23 33 100 345 | |
pickle_file = 'high_scores.pckl' | |
with open(pickle_file, 'rb') as file_handle: | |
unpickled_list = pickle.load(file_handle) | |
print(unpickled_list) | |
if __name__ == '__main__': | |
main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HighScore: | |
def __init__(self, score): | |
self._score = score | |
def __str__(self): | |
return str(self._score) | |
def __repr__(self): | |
return f'HighScore({self._score})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment