Welcome to file-handling-with-python, part of the practice-python-for-beginners learning series.
This repository helps beginners learn how to open, read, write, and append to files safely in Python β one of the most essential programming skills.
This repository teaches how to open, read, write, and append text files using best practices and introduces context managers (with blocks) to handle files efficiently.
file-handling-with-python/
β
βββ LICENSE
βββ README.md
β
βββ exercises/
β βββ write_to_file.py
β βββ read_from_file.py
β βββ append_to_file.py
β βββ file_utilities.py
β βββ tests/
β βββ test_write_to_file.py
β βββ test_read_from_file.py
β βββ test_append_to_file.py
β βββ test_file_utilities.py
β
βββ requirements.txt
- Opening and closing files
- Reading text data (
read,readline,readlines) - Writing and appending to files
- Using context managers (
with ... as) - Basic error handling for files
- Working with file paths
-
Clone this repository:
git clone https://github.com/practice-python-for-beginners/file-handling-with-python.git cd file-handling-with-python -
(Optional) Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install requirements:
pip install -r requirements.txt
-
Run tests:
pytest
By exploring the examples here, learners will be able to:
- Work with file input and output operations.
- Manage file data using context managers.
- Avoid common file-handling mistakes (e.g., forgetting to close a file).
All code is released under the GNU General Public License v3 (GPLv3).
See LICENSE for details.
Happy coding and practicing!