This is Python! (part 2)

Tags

, ,

This is the second post in a series for those who have never used Python but have used a programming language before. These posts are an introduction to this delightful and popular programming language.

The first post introduced Python’s most basic data types: int, float, str, bool, and None. In this post we’ll meet the list-like data types.

Continue reading

This is Python! (part 1)

Tags

, ,

There is a well-known movie line: “This! Is! Sparta!!” To begin the new year, here begins a series of posts under the rubric of “This is Python!” (Python isn’t quite as emphatic about things as Spartans, so it’s just one sentence with one exclamation point.)

These posts are meant for those who have never met Python but who have used a programming language before and know the general concepts. These posts provide a tour of the language.

Continue reading

Tk Calculator App Extra

Tags

,

The last three posts (see here, here, and here) have taken us through Python’s standard tkinter module from the basics to a simple windowed application with a text window for editing and the usual features for loading and saving text files.

I mentioned in the second post that I’d “implement a simple word-counter to replace the calculator parsing and execution code.” That’s what today’s short end-of-the-year post is about.

Continue reading

Python Prefix Calculator App

Tags

, , , , ,

In the last post we used the Python tkinter module (which is standard) to build a shell window for script-based calculator app. To do anything useful, the shell needs a back-end calculator object to implement script parsing and executing functions.

In this post we’ll look at code for a script-driven prefix calculator that can be easily extended to include other (mathematical) functions.

Continue reading

Python Tk Calculator App

Tags

,

The previous post laid out the basics for creating windowing (GUI) apps in Python using the tkinter (Tk Interface) module. The module has been part of the standard library since Python versions 2.7 and 3.1.

In this post, as a small seasonal gift, I’ll start presenting a working GUI application — a script-driven pre-fix calculator with variables. Between the calculator code and its window code, there is too much for one post, so there will be (at least) a second part next week.

Continue reading

Tk Windows in Python

Tags

,

Python has included the Tk interface module (tkinter) since versions 2.7 and 3.1. The module is a binding to version 8.5 of the Tk GUI suite for making windowing applications. My first installed version of Python was 2.7, so I’ve been aware of the module for over ten years but never explored it.

At the beginning of this month, I decided to dive in. It led to an intense two-week bout of 12+ hour days, but I emerged with working apps (and my sanity). This post and ones to come document and share what I’ve learned.

Continue reading

Dual Numbers in Python

Tags

, , , ,

The last two weeks I’ve been on a serious coding binge teaching myself Python’s Tk module. Once I wrap things up, I plan to publish a series of tutorial posts.

In the meantime, here’s a trick I learned recently that allows one to start with a series of data point and use those to (quickly!) generate a set of corresponding data points that are the derivative of the function implied in the first set. The trick uses something called the dual numbers.

Continue reading

Python Decorators, more

Tags

, , ,

Last time I explored a number of useful Python decorators. The post was a revisit to a topic I first posted about five years ago [see Python Decorators, part 1 and Python Decorators, part 2]. Back then I didn’t really know what to do with decorators, but I could see they were useful.

Since then, I’ve found many applications for them, hence the revisit to the topic. In this post, we’ll continue looking at useful applications. If nothing else, they may provide some ideas for decorators of your own.

Continue reading

Python Decorators, redux

Tags

, ,

I wrote about Python decorators five years ago. [See Python Decorators, part 1 and Python Decorators, part 2] At the time, they were new to me, and I hadn’t thought of good use cases for them. Or really, even just good ways to use them.

But that changed during the last five years as I’ve had occasions to actually use decorators in code. They are extremely handy in certain situations. Today’s post takes a more useful look at Python decorators.

Continue reading

Byte Multiplication Trick

Tags

, , ,

I’ve been working on an arbitrary-precision numeric class (in Python) that stores numbers in what amounts to base-256 — that is to say, in machine-native binary. It differs from the variable-length integers in Python by supporting fractions (and from Python’s Decimal number type by being binary).

It occurred to me I could implement multiplication with a lookup table rather than actually doing the math (at the CPU level, that may be what in fact is going on). So, I thought I’d compare the two implementations.

Continue reading