Vigenère cipher simplified implementation

This is not an other dissertation on Vigenère cipher. This encryption algorithm is profusely discussed in cryptography literature. Here is rather a simplified yet efficient implementation of it. The goal of this article is not to about debating the theory of Vigenère cipher. I rather just want to focus on its implementation after I have seen several awkward ways of proceeding to it on different online programming forums. This question on Code Review website is an example of such implementations where code duplication is obvious but which the pre-existing answers did not address. [Read More]

Installing Selenium drivers on Ubuntu

Here is a common exception raised when trying to invoke selenium’s webriver component for browser automation launching. Here is how to fix it. For a professional need, I installed selenium testing framework on Ubuntu 17.04 LTS within a virtual environment I created using the recommended method I found on the documentation: pip install selenium Chrome I then tried to launch my website on Chrome: from selenium import webdriver driver = webdriver. [Read More]

Do not make a direct use of function parameters

Today, I have answered a question on Code Review website. The OP’s code sample itself was simple, but a user commented my answer stating that he never heard about function’s parameters should not be used directly. Following my answer to this question, I wrote this: “Whatever the programming language you use, do not use the parameters inside your function” and I explained what I meant: def my_function(param): par = param # Now work with "par" instead of "param" A user was curious about the last section of my thread and commented: “Is your point on ‘do not use function params directly, no matter what language’ (paraphrased) definitely correct? [Read More]

Tkinter best practices

Tkinter is the standard Python interface to Tk/Tcl GUI toolkit. Programmers often wonder how to structure their tkinter program. In this article, I am going to answer to a question posted on StackOverflow which contributions drift away from some of software engineering fundamentals. I see many questions posted on StackOverflow and CodeReview asking for tkinter best practices and improvements. While many of the contributions to those questions are interesting, they also teach bad and even harmful coding habits that result in scalability and maintenance issues. [Read More]

How to contribute to Flask

I am an opensource advocate. I want to contribute to Flask microframework. So I followed the official documentation on GitHub where I stumbled on 6 issues. The problem is that the documentation itself is misleading and that can be a good starting point. I want to contribute to Python Flask microframework. I read its CONTRIBUTING.rst file from GitHub. I encountered few issues because the documentation is not clear for me. It even sounds to be outdated. [Read More]

Introduction to Flask

This articles shakes hands with Python web development. It introduces the Flask microframework. It is rather a light and soft introduction in that it tells the newbies only what they need to know at this stage. It is intentionally kept short, simple and without confusing terminology. What is Flask? Installation Components Example What is Flask? Flask is a web development Python framework. More precisely, it is a microframework because it is so small that you could quite quickly be familiar with its source code. [Read More]

XML parsing with minidom

This is a basic tutorial to introduce minidom. In fact, this is not really a tutorial but just a few list of notes about this library as there is already a short but good tutorial about it online1. Let us consider this XML data: <?xml version="1.0" encoding="UTF-8"?> <stock> <product id="p1"> <title>Product 1</title> <reference>999-X</reference> <price>20.10</price> <dimensions> <weight>4</weight> <height>50</height> <width>20</width> </dimensions> </product> <product id="p2"> <title>Product 2</title> <reference>999-B</reference> <price>55.5</price> <dimensions> <weight>3.99</weight> <height>50</height> <width>20</width> </dimensions> </product> </stock> You can either save this as an XML file or consider it as a string. [Read More]

Python singleton design pattern

This article describes the main strategies to implement the Singleton design pattern in Python. I am going to skip the whole very subjective “use and do not use singleton” conundrum. Introduction Definition Implementation Module Traditional Decoractor Metaclass Borg Conclusion Introduction There are developers who simply call to “ban” this design pattern. Personally, I think while it does not respect the single responsibility principle, the singleton may still be useful in situations where you need to control a concurrent access to a shared resource, or want to use it to implement other design patterns. [Read More]

tkinter: the SaYa idiom

Python is a paramount programming languages. The same is to be said about user graphical interfaces. SaYa is an idiom I devised for tkinter developers to help them build less error-prone applications. Background Explanation Motivation Statement Advantages Background This morning I landed on this question asked on StackOverflow where the OP stumbled on this error he shared through his/her comment to my answer: NoneType' object has no attribute 'destroy' The origin of the problem is that the OP created a button widget within the class initializer and positioned in the same time: [Read More]

Python unit testing

Introduction I first thought to write about TDD (Test-Driven Development), but given the list of reminders I have to emphasize and which would lead to a very lengthy article, I decided to shrink the work into smaller edible articles. You can find a lots of documentation about unit testing with Python on the Internet, so why am I adding this brick? That is not your business. But landing on this page will be useful for you as I found highly ranked -by Google- online resources discussing Python unit testing where the authors either mislead you at best or misinform you, not because they do not know but because they do not give importance to details. [Read More]