Tag: python

  • How to Debug Code (with Python Examples)

    How to Debug Code (with Python Examples)

    Often in your programming career, you will inadvertently write flawed code that introduces some fault into your codebase. These faults are called bugs and the activity of fixing bugs is called “debugging.” Of course, as developers, we try to write correct code every time, but writing bugs is simply a fact of life for programmers. The ability to diagnose and fix bugs is the mark of an experienced and talented developer and is foundational for advanced troubleshooting. In this article, we’ll go over some techniques for effective debugging and introduce you to PDB, the Python debugger. At the end of this article, you’ll be ready to not only troubleshoot and fix your own code, but to diagnose and debug existing code as well.

    (more…)
  • Python Exception Handling and Customization

    Python Exception Handling and Customization

    Like bugs, exceptions are inevitable when developing software, especially as the complexity of that software increases. Sometimes exceptions are surprising, other times we can anticipate them coming. How a program responds to the occurrence of exceptions is called exception handling, and as programmers, we can define and customize exception handling. In this chapter, we’ll learn what exceptions are, how to handle them, and how to make our own.

    (more…)
  • Test-Driven Development with Python: a Primer

    Test-Driven Development with Python: a Primer

    Making sure the software we build works the way we (and our customers) want it to work is called, unsurprisingly, software testing. Software testing is an enormous topic; indeed, there are entire books, courses, conferences, academic journals, and more about the topic. One can even make a career out of testing software. We couldn’t possibly scratch the surface of the complexity involved in software testing in this article, so we’ll only focus on a topic most relevant to us as programmers: test-driven development.

    (more…)
  • Delegate and Decorate in Python: Part 3 – Reusable Decorators

    Delegate and Decorate in Python: Part 3 – Reusable Decorators

    Note: This is not about Python’s language feature called decorators (with the @ symbol), but about the design patterns called “decorator” and “delegate.”

    In the final installment of this series, we will take the universal concepts of delegation and decoration and put them into a base Decorator class. Doing so will allow us to abstract the universal functionality these patterns to be inherited by more specific decorator classes, maximizing code reuse. Let’s dive in.

    (more…)
  • Delegate and Decorate in Python: Part 2 – The Decorator Pattern

    Delegate and Decorate in Python: Part 2 – The Decorator Pattern

    Note: This is not about Python’s language feature called decorators (with the @ symbol), but about the design patterns called “decorator” and “delegate.”

    In the previous article, we learned how to implement the Delegation pattern in Python. With this knowledge, we’ll now learn about the Decorator pattern, which will make use of delegation. We’ll learn about when we might use it and implement a couple of examples.

    (more…)
  • Delegate and Decorate in Python: Part 1 – The Delegation Pattern

    Delegate and Decorate in Python: Part 1 – The Delegation Pattern

    Note: This is not about Python’s language feature called decorators (with the @ symbol), but about the design patterns called “decorator” and “delegate.”

    In this series we’re going to learn two very useful design patterns: the delegation pattern and the decorator pattern. Each pattern is useful in that they help us enforce the single responsibility principle of object oriented programming. Getting these patterns to work as expected in Python requires a relatively deep dive into Python syntax as well as the always scary technique of metaprogramming. Let’s jump in!

    (more…)
  • Getting Started With Browser Automation Testing in Python

    Getting Started With Browser Automation Testing in Python

    Developers have unit tests to test atomic functionality and integration tests to test system interoperability. Web developers have to take it a step further and test actual browser behavior. This can be done in many ways, but most often it’s with some implementation of Selenium webdriver and an xUnit testing framework. In this article, I’m going to show you how to write a basic framework in Python to get your tests able to interact with a browser.

    (more…)