Skip to content

Instantly share code, notes, and snippets.

@herikwebb
Last active April 27, 2021 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herikwebb/e481b40c9ed6465ad1082d9c33dc76c9 to your computer and use it in GitHub Desktop.
Save herikwebb/e481b40c9ed6465ad1082d9c33dc76c9 to your computer and use it in GitHub Desktop.
def write_to_file(filename, grades):
with open(filename, 'w') as f:
for v in grades.values():
if isinstance(v, list):
blah = ' '.join(str(z) for z in v)
f.write(blah + '\n')
else:
f.write(str(v) + '\n')
grades = {'Name': 'George Mason', 'Projects': [100.0, 100.0, 95.0, 100.0, 100.0, 95.0], 'Homeworks': [100.0, 100.0, 90.0, 100.0, 100.0, 100.0], 'zyBooks': [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 90.0], 'Quizzes': [90.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 90.0, 90.0], 'Midterm': 95.0, 'Final': 100.0}
filename = "C:\\Users\\herik\\git\\blah\\writetofile.grades"
write_to_file(filename, grades)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment