Alex Carney

Creating a CPython Extension

Previously, as part of my exploration into how programming languages are implemented, I wrote a very simple AST evaluator that knew how to add and multiply floats together. Since constructing these ASTs by hand is quite painful I thought it would be fun to come up with a frontend to my “programming language” which could do it for me.

Now your typical frontend would be some kind of parser built into the compiler/interpreter. However, while I’m definitely interested in parsing I don’t quite feel like tackling that just yet. Instead I’m going to have Python be the frontend and embed my toy language into it via a CPython Extension


Introducing Stylo Doodles!

A few weeks back at PyConUK I gave my first lighting talk at a conference. During that talk I spoke publically about stylo for the first time. Stylo is a Python library that I have been working on for just over a year and a half and it aims to make the creation of images easier by bringing together ideas from programming and mathematics.

Version 0.6.0 was recently released which included the first feature that wasn’t written by me! It’s very exciting not only to see other people starting to take an interest in the project but taking the time to make a contribution!

Now that stylo seems to be getting to the point that it might me useful to other people wouldn’t it be great if there was a community driven example gallery that people could get inspired by? - Well now there is! And it’s called Stylo Doodles



A CPython extension that embeds the simple-ast program into Python. >>> import ccalc >>> expression = (ccalc.Literal(1) + 2) * 3 >>> expression Multiply<Plus<Literal<1.0>, Literal<2.0>>, Literal<3.0>> >>> ccalc.eval_ast(expression) 9.0 Building It’s probably worth creating a virtual environment to work in .cli-command::before { content: "$ "; } python -m venv .env Assuming you have a C compiler available, building the extension is as easy as running the following command More...

Custom Jupyter Kernels

It’s possible to create custom Python environments for use within a Jupyter notebook without having to run a jupyter server from each of them. The following steps will allow you to have a single jupyter server running and have it use a variety of Python environments in its notebooks Create a virtualenv and install any packages that you want available pip install ipykernel ipykernel install --user --name <envname> --display-name <display name> Then the new environment should become available in the Change kernel menu

Python 2.x Gotchas

While at the time of writing (May 2019) the death of Python 2 is just around the corner since I’m working in an enterprise environment I’m sure I will be dealing with Python 2.x code for some time to come. To that end here are some gotchas to keep in mind. Missing Features In the 10+ years since Python 3’s release it’s not surprising that it has accumlated a large list of features that simply don’t exist in Python 2. More...

Python 3.x Gotchas

Beware pathlib on 3.5 While pathlib exists in Python 3.5, it’s not fully integrated yet. Passing a pathlib.Path object to the built-in open method will result in a surprising error TypeError: invalid file: PosixPath('path/to/file.txt') In this situation it’s better to call the path’s open() method instead.