Python

Is string formatting in Python safe to use or not?

The mighty and powerful f-strings. Well, they are only a sugar syntax on string.format, but whatever. Here I will look at one of the usage scenarios that you should not commit - taking format string from the user. Well, I had to do it in my project, so…

Python evolution with Luciano Ramalho - summary of podcast

In one of the recent episode of Python podcast, Toby Macey was interviewing Luciano Ramalho. I have a lot of respect for this developer as for me it is one of the last true “Pythonista’s” left in the world. During one hour he talks about his Python beginnings, writing “Fluent Python” book, and his view about new Python features. I recommend listening to the whole podcast, but here is a summary of his opinions about Python evolution.

First look at WSGI and PEP 3333

WSGI - Web Server Gateway Interface. This is Python standard interface between web server software and web applications. The specification was created in 2003 and described in PEP 333, further updated in 2010 in PEP 3333, with backward compatibility to prepare for Python 3 changes.

Playing with Python: Boolean of empty containers

It is funny that when one decides to refresh the basics of Python, watches the first video about types and is already stuck for an hour testing edge cases and wondering why? Let’s explore the bool function with empty containers.

Simple game menu in Python and Godot

Recently I have started to dive into game programming a bit more. Coming from Python with Pyglet, my current choice is Godot game engine. I created a simple text-based game menu in both to see what is easier for someone without any prior experience.

Singleton Design Pattern in Python

Recently I dived into design patterns a little bit, to refresh a rusty knowledge. It is something we are using in Python daily, however not often realizing that. And I like reading those religious debates between programmers. One of them is the usage of Singleton in Python. Let’s see what is Pythonistas take on this beloved pattern.

Concurrency in Python - intro

The first paragraph from Python documentation about concurrency titled “Concurrent Execution” mentions a few phrases like, CPU bound, IO bound, event-driven cooperative multitasking or preemptive multitasking. In this intro post to concurrency, let’s clarify these definitions.

Parametrizing tests with pytest

In pytest we can parametrize in three different ways:

  • pytest.fixture() - allows to parametrize fixture functions
  • @pytest.mark.parametrize - allows to define arguments for a test function or class
  • pytest_generate_tests - allows to define custom parametrization schemes

This article presents a few examples of how to use parametrization in pytest using @pytest.mark.parametrize. The article starts from the basic tests, and end with the usage of ids and indirect.

Summary: Assignment Expressions - PEP 572

The famous PEP 572, and one of the reasons Guido Van Rossum - Python BDFL - retired from decision process (stepped down as BDFL). It is called “Assignment Expressions”, and is about adding new syntax := that will allow assign to variables within an expression.

Summary: Python Positional-Only Parameters - PEP 570

In Python, we have positional and keywords arguments. With the introduction of new syntax in PEP 570, we can specify positional-only parameters in Python function definitions. This feature is especially useful for library developers, to ensure correct usage of an API. Let’s discuss what this PEP is all about.

Summary: Python Enhancement Proposal - PEP 1

PEP (Python Enhancement Proposal) are describing new features, processes or other guidelines and information. They are written primarily for core CPython or other implementation developers. But actually, they are fun and interesting read for a regular developer as well. It is because the authors are really polishing the documents (standards are rigorous) and in addition to documentation, we can get to know proposed or already implemented features. Anyway, fun to read. One disadvantage, PEPs are sometimes long.

Series: Python Interview Questions #3

Task: Define the function that takes two parameters (dictionaries as default). Without modifying original dictionaries return the new one that includes all key and value pairs however, if key repeats itself, then add values

a = {'a': 5, 'b': 1, 'c': -1, 'd': 1}
b = {'a': 1, 'b': 5, 'c': 1, 'e': 1}
solution = {'a': 6, 'b': 6, 'c': 0, 'd': 1, 'e': 1}

Python Interview Questions for Web Developer Position

My little tour on Python Web Shops is over for now. It has been an excellent chance to see what is going on in the town. I have been applying mainly for a web developer position. Below is a list of few interview questions I have got. I will answer the most interesting or ones that require more in-depth research in the next articles.

Python dictionary is now officially ordered!

Python 3.5 brought us 4-100 times faster OrderedDict thanks to its implementation in C, before was written in Python. Python 3.6 improved a standard library dictionary, by making it use more compact representation. Now dictionary could use 20% to 25% less memory compared to Python 3.5, and the order of items was kept but as suggested it was only an implementation detail and should not be used officially (backwards compatibility). Well, in Python 3.7 it has been approved.

Which one should we use now? Standard dict or OrderedDict ?

Codility Demo Test

I have had a chance to solve Codility demo test. It is available for free, and you can try it unlimited times. While I do not believe that such tests correlate to typical real-world programming tasks, they are often used as a first interview filter by some companies. Here I show a few Python variations for the solution.

Python and PostgreSQL deployment to CircleCI

Update: Similar setup but for CircleCI 2.0 is HERE

Deploying to CircleCI as easy as creating yaml file (sometimes you even do not need it as Circle will automatically recognize structure and behavior). But usually it is better to setup at least basic configuration. The problem begins with more complicated functionality and CI documentation is minimal, or to say ‘very hacker friendly’.

My problem was how to use build-in PostgreSQL database with Python application. This is quick tip how I solved it.