
Using Files and Libraries -- Learning Python from Scratch
Brian Clark π‘
Updated on
γ»5 min read
learning-python (21 Part Series)
The following are notes and details recapping a past live stream where we live code together. The idea behind these streams is that they provide real-world examples of running into problems and solving them or working towards solving them live. Enjoy this latest one on Python ππ
Wednesday - October 9, 2019
Goals
β
Warm up/Catch up with chat
β
Stretch/break
β
Learn about using files and libraries in Python
β
Closing and raid @cmgriffing
Results
- Cloned our repo we created in GitHub from last session (repo)
- Learned about working with files - reading, writing, etc.
- Learned about libraries
Things we learned
- A zip file is a compressed format of files and folders
- What indentation errors indicate
- How to show whitespace in vs code
- We can't catch exceptions that are system exit type errors
- Reminder of what gitignore does
- Via svmihar: check out pipenv in a future episode
- Use 'pip freeze' to save the libraries we depend upon in our projects
- What the '>' symbol does in the terminal
- Via ShephiZaragoza: as a note, > will add, >> will overwrite the file
- Via phrakberg: >> Appends, > overwrites
- The open() function is used to open files on which the system our program is running
- Always use close() function when we're done with a file
- We can use context managers to safely open files and it will automatically use close() for us under the hood
- What is JSON? JavaScript Object Notation
- When opening a file we need to keep in mind where exactly that file is on the system in order to properly access it
- Via joaostriker: you use forward slahes to find a path in windows , or, you do full path with with backslash instead
Next Steps
- Cover the API's section of the learnpython.dev course by Nina
Things to Review & Notes
- TODO clarify the open() function modes to understand them better
Resources
- Our Code Repository
- Nina Zakharenko's course we're following: Learn Python
- Python Cheat Sheet
- Microsoft Developer's Python for Beginners
More of Nina Zakharenko's courses
VS Code Extensions Shown/Used
Clips
Clips are a feature on Twitch that let you cut and capture segments of the live stream in the moment (up to 60 seconds). See how to use clips on Twitch for more details. The following are some fun moments captured from this stream:
- How to open files using a context manager in Python
- Trying out opening a file in Python
- Python Import Analogy: "Excuse me there I'd like to import your space into my space..." π
Segments
Links not working on Twitch? It's most likely because Twitch will only save my stream recordings for about 60 days. Use the YouTube link at the top of this page instead.
This table helps point out different segments of the stream (highlighted in bold) or moments we learned something (not bold). The timestamps link to the video on Twitch at that point in the recording. If you'd like the YouTube link above will have similar timestamps and link to those same points in the recording as well.
Timestamp | Topic |
---|---|
00:07:28 | Kick it off |
00:12:11 | Recap from last episode |
00:18:36 | Learning how to clone from the git repository we set up last episode |
00:22:22 | A zip file is a compressed format of files and folders |
00:31:35 | What indentation errors indicate |
00:34:28 | How to show whitespace in vs code |
00:37:00 | We can't catch exceptions that are system exit type errors |
00:39:40 | Reminder of what gitignore does |
00:41:28 | Setting up the virtual environment after cloning the git repository |
00:49:52 | Via @svmihar: check out pipenv in a future episode |
00:58:59 | Use 'pip freeze' to save the libraries we depend upon in our projects |
00:59:45 | What the '>' symbol does in the terminal |
01:03:49 | Via @ShephiZaragoza: as a note, > will add, >> will overwrite the file |
01:05:19 | Via @phrakberg: >> Appends, > overwrites |
01:10:53 | Start break |
01:17:54 | Back from break and start stretch |
01:21:19 | Start learning about working with files in python |
01:22:46 | The open() function is used to open files on which the system our program is running |
01:24:42 | Always use close() function when we're done with a file |
01:26:20 | We can use context managers to safely open files and it will automatically use close() for us under the hood |
01:33:08 | What is JSON? JavaScript Object Notation |
01:38:54 | Writing code to open a cities.json file |
01:41:12 | When opening a file we need to keep in mind where exactly that file is on the system in order to properly access it |
01:55:32 | Via @joaostriker: you use forward slahes to find a path in windows , or, you do full path with with backslash instead |
02:23:05 | Working with libraries |
02:40:10 | Close and recap |
YouTube Video
Get connected with Cecil Phillip
Get connected with Brian Clark
If you're looking to take the next step with Python check out these courses by Nina:
Thanks for reading this article. If you're interested in finding more content from Microsoft Cloud Advocates check out this monthly curated newsletter: Developer Community Newsletter
learning-python (21 Part Series)