From 6e8d72a66d2355df41089cba92d780ed7be0589b Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Sat, 16 May 2020 21:38:14 -0400 Subject: [PATCH] Implement initial read in of file --- documents/references.md | 7 ++++++- main.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/documents/references.md b/documents/references.md index 764a3d6..b813060 100644 --- a/documents/references.md +++ b/documents/references.md @@ -5,7 +5,9 @@ All references to external logic. Includes anything from stack overflow links to notes about logic from previous works. -## Logging Logic +## Python + +### Logging Logic The contents of `resources/logging.py` (and all associated logic) originally started from me trying to learn how to log information through Django (the Python Web Framework) using a Dictionary type format. (See <https://docs.djangoproject.com/en/dev/topics/logging/> for reference). @@ -15,3 +17,6 @@ and school assignments. After repeatedly importing and updating as needed, the l what it is today. Logging files can be found in `resources/logs/`. + +### Reading Files +<https://www.pythonforbeginners.com/files/reading-and-writing-files-in-python> diff --git a/main.py b/main.py index 672e0e4..ed3f932 100644 --- a/main.py +++ b/main.py @@ -14,8 +14,35 @@ logger = init_logging.get_logger(__name__) def main(): + """ + Program main. + """ logger.info('Starting main()') + calc_part_1() + + +def calc_part_1(): + """ + Logic for "part 1" of assignment. + """ + student_array = [] + + # Open file. + with open('./documents/data.online.scores.txt', 'r') as student_scores_file: + # Read in each line and save to our struct. + for line in student_scores_file: + # Split on tabs. + split_line = line.strip().split('\t') + + # Save to struct. + student_array.append({ + 'id': int(split_line[0]), + 'midterm': int(split_line[1]), + 'final': int(split_line[2]), + }) + + logger.info(student_array[len(student_array) - 1]) if __name__ == '__main__': -- GitLab