filmov
tv
Learn Python E5: File Handling | Jameson

Показать описание
Read and write files with Python. Learn about file handling with Python to persist data to hard-drive to retrieval when it's needed.
Season 1 - Episode 5 | Featuring: Jameson Irish Whiskey
In this video, we briefly touch on the os (operating system) module from the Python standard library and discuss a couple uses for it.
In the majority of the video I demonstrate ways to use the open function to open files on your machine for reading and writing - programatically with Python. We learn about the read and write modes of the open function to perform different operation on text files.
While we can implement the open function by opening and closing the file, I demonstrate best practice of using a context manager to handle the external resource management with Python - sounds hard, but is very simple and makes file handling very easy. I also touch on the underlying file pointer and how to reset the pointer position in the code with the .seek() method.
Most data files that we consume programatically are structured data files. We'll walk through opening a .dsv file (delimiter seperated values - in this case the text file contains values separated by pipe). We will use the .split() method in a couple different ways to construct iterables of rows and values for processing.
For the final exercise, we will start a new command line app that will keep track of my whiskey tasting notes. The major usability flaw of the sales tax calculator was that we were not able to save the state of the app - we couldn't save the data. For the new whiskey review app, we will build-in the ability to save the app data to a file so that state of the app is persisted between sessions. NOTE: mid-exercise I do make a mistake that is corrected later in the video - the mistake is called out in a text-box on-screen when it occurs (sorry guys).
I hope you find these videos helpful, and I look forward to interacting with you in the comments~
Season 1 - Episode 5 | Featuring: Jameson Irish Whiskey
In this video, we briefly touch on the os (operating system) module from the Python standard library and discuss a couple uses for it.
In the majority of the video I demonstrate ways to use the open function to open files on your machine for reading and writing - programatically with Python. We learn about the read and write modes of the open function to perform different operation on text files.
While we can implement the open function by opening and closing the file, I demonstrate best practice of using a context manager to handle the external resource management with Python - sounds hard, but is very simple and makes file handling very easy. I also touch on the underlying file pointer and how to reset the pointer position in the code with the .seek() method.
Most data files that we consume programatically are structured data files. We'll walk through opening a .dsv file (delimiter seperated values - in this case the text file contains values separated by pipe). We will use the .split() method in a couple different ways to construct iterables of rows and values for processing.
For the final exercise, we will start a new command line app that will keep track of my whiskey tasting notes. The major usability flaw of the sales tax calculator was that we were not able to save the state of the app - we couldn't save the data. For the new whiskey review app, we will build-in the ability to save the app data to a file so that state of the app is persisted between sessions. NOTE: mid-exercise I do make a mistake that is corrected later in the video - the mistake is called out in a text-box on-screen when it occurs (sorry guys).
I hope you find these videos helpful, and I look forward to interacting with you in the comments~