What you'll learn:
- Reading data from a text file
- Reading data from a spreadsheet
- Why dictionaries are useful for storing information in a structured way
Just a few practical examples:
- Reading data from a text file and turning it into a string
- Reading data from a text file and turning it into a list
- Reading data from a spreadsheet and looping over its contents to use the data
- Using dictionaries to store information in a structure like a phonebook
Examples in real projects:
- Open a text file containing a list of schools: Used in https://shannonvturner.com/seriously
- Build a dictionary with data about a school to turn it into GeoJSON used for mapping: Used in https://shannonvturner.com/seriously
- Ensure that a user-created Metro Map is a valid map (it has stations and rail lines) so that it can be saved and rebuilt: Used in https://metromapmaker.com
- If this movie's rating is disputed, display a caveat for the rating. Otherwise, don't edit the rating: Used in https://shannonvturner.com/bechdel
Code Samples:
- https://github.com/shannonturner/python-lessons/tree/master/section_07_(files)
- https://github.com/shannonturner/python-lessons/tree/master/section_10_(dictionaries)
Exercises:
- States: https://github.com/shannonturner/python-lessons/blob/master/playtime/lesson03_states.py
- Contacts: https://github.com/shannonturner/python-lessons/blob/master/playtime/lesson03_contacts.py
Concepts Learned:
- File handling
- Dictionaries
Keywords learned:
- with
- as
- None
Functions learned:
- open()
File Methods learned:
- .read()
- .write()
Dictionary Methods learned:
- .get()
- .keys()
- .items()