Python Descriptors, part 2

Tags

, , ,

Python has the useful notion of descriptor objects, which give object attributes control over how they are accessed. Descriptors enable calculated-on-the-fly attribute values and can prevent or control modification of data values.

The previous post covered the basics. In this post, I’ll dig deeper into Python descriptors with some more involved examples. This post assumes the basics covered in the previous post.

Continue reading

Python Descriptors, part 1

Tags

, , ,

Python has the useful notion of descriptor objects as well as the built-in property() function to make using them in the most common cases — read-only and calculated instance attributes — quite easy.

In this post I’ll explore Python descriptors with lots of examples demonstrating how to use them. Descriptors are an important aspect in understanding Python and using it effectively.

Continue reading

Why 1s and 0s?

Tags

, , , ,

Quite some time ago, I posted about this on my main blog, but it has occurred to me that, firstly, it might be time for an update, and secondly, that a post about why computers use 1s and 0s is better suited here on my programming blog. (Especially as this is the 101st post!)

It turns out there is a very good reason computers use 1s and 0s, and while it is possible to use other numbers, the 1s and 0s are all that is needed.

Continue reading

Musical Scale Modes Table

Tags

, ,

Mathematician and educator John Baez has an excellent series of blog posts about music theory. The seventh concerns generating scales by using notes separated by fifths. Shifting the start point generates the seven major scale modes. Shifting the root key generates those seven modes in the twelve keys (a total of 7×12=84 scales).

John asked if any of his readers would be interested in creating that table of all 84 rows. It sounded like — and turned out to be — a fun exercise. This post explores in detail the Python solution I came up with.

Continue reading

Calculating the Number e (in Python)

Tags

, , ,

It has been almost a year since my last post here. I haven’t been idle code-wise, but I have been too distracted by Real Life to do any blogging here. My publication rate is way down on my main blog, too.

To get me posting here more, I think I need more of a focus on casually documenting my own little projects rather than Code Wise articles. Those take more work than I seem willing to put in these days. With that in mind, I have some trivial Python fun to share…

Continue reading

Regular Expressions

Tags

, , ,

There are many general skills a programmer should have to be effective and valuable. Some are very general — for instance, the ability to learn and to think abstractly — but some are more specific — various tools and tricks of skilled programming.

Among those tools are several non-programming languages all programmers should know. Those include HTML, XML, SQL, and an old one whose name doesn’t end with “L” — Regular Expressions (aka REs, aka RegEx or RegExp).

Continue reading