// What's Next · Done · The Associate Track
Software Engineering Principles in Python
Completed Nov 08, 2026 · 4 hrs
Study notes on software engineering fundamentals in Python, covering modularity, documentation, testing, and version control, plus hands-on work with packages, PEP 8 style, classes, inheritance, and testing tools.
Software Engineering Principles
- Modularity: Dividing code into shorter functional units to improve readability, maintainability, and reuse across projects.
- Documentation: Explaining code through comments, docstrings, and self-documenting code so users and future you can read it.
- Automated Testing: Running tests automatically to save time over manual testing, find more bugs, and check code anytime.
- Version Control & Git: A topic listed as a follow-up for managing code versions, not covered in these notes.
Packages and Style
- PyPI: The Python Package Index, a platform for leveraging published packages.
- pip: The package installer, a recursive acronym for Pip install Packages, used to install packages and dependencies.
- help(): A built-in function that prints documentation for a package, class, method, or object.
- PEP 8: The de facto style guide for Python code, focused on readability.
- pycodestyle: A package that checks code for PEP 8 violations across files and reports their location and error code.
Package Construction
- package structure: A directory plus an __init__.py file, where the directory name becomes the package name.
- __init__.py: The file that tells Python a directory is a package and can expose key functionality to users.
- submodules: Additional Python files inside a package, imported with dot notation such as my_package.utils.
- relative import: A dot notation import such as .utils, required when packaging Python 3 and above.
- setup.py: A file using setuptools.setup that tells pip how to install the package and supplies metadata for PyPI.
- requirements.txt: A file listing dependencies and optional version constraints, installed with pip install -r requirements.txt.
Classes and OOP
- class: A blueprint created with the class keyword, documented with a docstring, and initialized with __init__.
- self: The first argument of instance methods, referring to the instance being created or used.
- non-public methods: Methods named with a single leading underscore, intended for internal use and carrying less documentation and stability.
- DRY principle: Don't Repeat Yourself, the rule against copy-pasting code so a bug is fixed once.
- inheritance: Passing a parent class's methods and attributes to a child class while adding new functionality.
- super(): A function that calls the parent class's __init__, improving maintainability and helping multiple inheritance.
Documentation and Readability
- comments: Inline notes explaining why code does something, visible only in source code.
- docstrings: Triple-quoted documentation for functions, classes, and scripts, shown when help() is called.
- Zen of Python: A list of readability guidelines viewable with import this, including readability counts.
- self-documenting code: Descriptive naming that makes code describe what it does, such as is_boiling.
- refactoring: Splitting long functions that do several things into smaller, descriptively named functions.
Testing and Tooling
- doctest: A module that runs docstring examples via doctest.testmod() and reports failures.
- pytest: A testing framework that finds test files and functions by name and checks them with assert.
- Sphinx: A tool that transforms docstrings into HTML documentation.
- Travis CI: A continuous integration service that runs tests automatically on changes and on a schedule.
- Codecov: A tool that reports test coverage so untested code can be found.
- Code Climate: A tool that analyzes code readability and flags functions that are too long or confusing.
// Module notes
Software Engineering Principles
Software engineering is code hygiene for data science, and the course is built on four habits that decide whether your exam code reads clean or spaghetti.
- Modularity divides code into shorter functional units, improving readability, maintainability, and reuse; Python uses packages, classes, and methods.
- Documentation helps collaborators and future you through comments, docstrings, and self-documenting code.
- Automated testing saves time over manual testing, finds more bugs, and runs anytime.
- Version Control & Git is recommended as a follow-up topic, not covered in these notes.
The exam will test this hygiene and organization directly, so these are the four habits to carry into every exercise.
Using Packages and Reading Documentation
Python's ecosystem pays off the moment you treat packages as finished solutions, not code to rebuild.
- Packages are installed from the Python Package Index, or PyPI, with pip, a recursive acronym for Pip install Packages.
- pip install numpy installs a package along with its dependencies.
- pip install -r requirements.txt recreates an environment from a requirements file.
- help() prints documentation shipped with a package, class, or object, such as help(numpy.busday_count).
Writing that documentation is the developer's job, and future-you is a user who benefits. It saves a lot of wasted time and headaches.
PEP 8 and Package Construction
PEP 8 is the de facto style guide for Python, and its reason is simple: code is read much more often than it is written.
- Violations: import not at the top, inconsistent spacing, missing line breaks.
- pycodestyle reports file, line, column, description, and error code, using one-based indexing.
- A minimal package is a directory plus __init__.py, with a short, all-lowercase name.
- Submodules like utils.py use dot notation; relative imports such as .utils are required in Python 3.
- setup.py and requirements.txt make a package portable; pip install . installs it.
Watch the naming rules, because the same conventions govern packages, submodules, and the classes you will write next.
Classes, Inheritance, and DRY
A class bundles state and behaviour into one reusable blueprint: the class keyword, a CamelCase name, and an __init__ method, with self referring to the instance and passed automatically.
- Non-public methods use a leading underscore and are for internal use, with little documentation and possible breaking changes.
- The DRY principle, Don't Repeat Yourself, avoids copy-pasting code so a bug is fixed once.
- Inheritance passes a parent's methods and attributes to a child class.
- super() calls the parent's __init__ and aids maintainability.
- Multilevel inheritance extends the family tree; dir() and help() list attributes.
Note that help() shows only public methods, while dir() is exhaustive but not advised inside scripts.
Documentation, Testing, and Tooling
Comments explain why code does something and stay in the source; docstrings use triple quotes and appear when help() is called.
- The Zen of Python and descriptive naming support self-documenting code.
- Refactoring splits long functions that do several things into smaller, descriptively named functions.
- doctest runs docstring examples; pytest finds test files and functions by name and checks them with assert.
- Sphinx turns docstrings into HTML documentation.
- Travis CI runs tests on changes and on a schedule; Codecov measures test coverage and Code Climate analyzes readability.
Together these tools turn the same principles into practice, so untested code and unread code both become visible.
In plain terms
Writing Python well is like running a shared kitchen: every station, label, and recipe has to make sense to the next cook. Packages are the store-bought staples, PEP 8 the agreed layout, docstrings the labels on the jars, and tests the taster who catches a bad batch before it is served.
Worth sitting with
- Why does copy-pasting code still feel faster than writing a shared function, and what changes the moment a bug surfaces in three places?
- If a docstring example and a pytest test can both check the same function, which one should carry the edge cases, and why?
- What does a non-public method owe its users, and how do you decide whether a helper is central enough to expose in __init__.py?
// Where this fits
The concepts above are the ones this module turns on, and the notes below explain each in turn. The course page carries the whole track, and the certificate page carries the plan it belongs to.