Implementation

In this section, we will implement a banner generator. The idea is rather simple. We want to send some text to a function, and the function should generate a banner containing the text. Banners have some sort of style, for example, dots or dashes surrounding the text. The banner generator has a default style, but we should be able to provide our own style.

The function generate_banner() is our Template function. It accepts, as an input, the text (msg) that we want our banner to contain, and optionally the style (style) that we want to use. The default style is dots_style, which we will see in a moment. The generate_banner() function wraps the styled text with a simple header and footer. In reality, the header and footer can be much ...

Get Mastering Python Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.