Created
January 12, 2020 20:53
-
-
Save goedel-gang/a002e2a8aa5f6172f96b59574c5ad91b to your computer and use it in GitHub Desktop.
Saving integers
This file contains 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
some_data = [ | |
(1, 2, 3), | |
(4, 5, 6), | |
(7, 8, 9), | |
(100, 255, 0)] | |
def dump_data(data, filename): | |
with open(filename, "w") as data_file: | |
for tup in data: | |
print(" ".join(map(str, tup)), file=data_file) | |
def load_data(filename): | |
data = [] | |
with open(filename, "r") as data_file: | |
for line in data_file: | |
data.append(tuple(map(int, line.split()))) | |
return data | |
dump_data(some_data, "data.txt") | |
print("Loaded data back as:\n{}".format(load_data("data.txt"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment