Have you ever started on some creative work, and given yourself an arbitrary restriction within which to do it? Like making some pixel art, but you will only use black or white pixels. I think it’s quite a fun way to drive the creative and problem solving juices, to test the limits of the restriction and learn new techniques.

In the two most recent posts we focused on the Python object system. We learned what Python objects and Python types are, how they are defined and what determines their behavior. This discussion gave us a good understanding of how Python objects work in general. What we haven’t discussed is how particular objects, such as strings, integers and lists, are implemented. In this and several upcoming posts we’ll cover the implementations of the most important and most interesting built-in types. The subject of today’s post is int.

Read More

Python is my favourite programming language. Since I discovered it in 2004, programming in Python became my favourite hobby. I’ve tried to learn a few other languages and have never found one as friendly to beginners as Python. As readers of this blog know, these days I am particularly interested in tracebacks, and I am likely paying more attention than most to Python’s improvements in this area: Python is becoming more and more precise in the information that it provides to the users when something goes wrong…

Read More

People bash OO a lot these days, I’m increasingly coming to the opinion they’re right, at least in Python. My point here is not to argue that OO is bad per se, more that its introduction is simply unnecessary, AKA not useful.

Let’s see how we can create QR codes that look however we want, while preserving links. We’ll also show the world’s first working QR gif (as far as I know).

Dec 23, 2020

On November 29, version 1.7 of SymPy, a Python library for symbolic mathematics, was released. The new version brings a large number of enhancements and bug fixes, and some minor backward incompatibilities. While these are enumerated in detail in the release notes, we will take advantage of this opportunity to look at some of the things that can be done with SymPy and explore its interface options through several detailed examples.

Dec 8, 2020

Mypy is an optional static type checker for Python. It’s been around since 2012 and is gaining traction even since. One of the main benefits of using a type checker is getting errors at “compile time” rather than at run time.

Exhaustiveness checking is a common feature of type checkers, and a very useful one! In this article I’m going to show you how you can get mypy to perform exhaustiveness checking!

Dec 8, 2020

Python’s defaultdict is an incredibly useful tool to specify default values for missing keys (RealPython has a great primer on them).

I found I was taking up so much memory to store the value 0 for an algorithm which counted rather infrequent elements in a huge sequence split into many chunks. Using a defaultdict(int) for each distinct element to store which indices had a non-zero count of the respective element greatly optimised it, but I yearned for a defaultlist equivalent to standardise this approach and generally make my code more expressive.

Read More
Dec 4, 2020

Flat is a library for creating and manipulating digital forms of fine arts. Its aim is to enable experimentation with and testing of unpredictable or automated processes, to inspect the beginning of the “new”.

It grew out of the needs for generative design, architecture and art. The concept of “design” is more of a subject of study yet to be delved into, hence the fitter term for subtitle is “infrastructure”.

Nov 15, 2020

In this demonstration we will use Keras and TensorFlow 2.3 to explore data, normalize data, and build both a linear model and Deep Neural Network (DNN) to solve a regression problem. TensorFlow Core 2.3 includes tf.keras, which provides the high level (high abstraction) Keras Application Programming Interface (API) for TensorFlow. Keras simplifies the command and control of TensorFlow. The TensorFlow ecosystem also contains straightforward and simple vehicles for normalization and other common Machine Learning data preparation constructs.

Read More
Oct 20, 2020

Some of the new major new features and changes in Python 3.9 are:

  • PEP 573, Module State Access from C Extension Methods

  • PEP 584, Union Operators in dict

  • PEP 585, Type Hinting Generics In Standard Collections

  • PEP 593, Flexible function and variable annotations

  • PEP 602, Python adopts a stable annual release cadence

  • PEP 614, Relaxing Grammar Restrictions On Decorators

  • PEP 615, Support for the IANA Time Zone Database in the Standard Library

  • PEP 616, String methods to remove prefixes and suffixes

  • PEP 617, New PEG parser for CPython

  • BPO 38379, garbage collection does not block on resurrected objects;

  • BPO 38692, os.pidfd_open added that allows process management without races and signals;

  • BPO 39926, Unicode support updated to version 13.0.0;

  • BPO 1635741, when Python is initialized multiple times in the same process, it does not leak memory anymore;

  • A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall;

  • A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489;

  • A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384.

Read More
Python

News and discussion about the python programming language.

Created on Oct 20, 2020
By @root