• Home
  • About
    • About The Coder
    • Language List
  • Code Rules
    • #1: Clarity Trumps Everything
    • #2: Source Code is for Humans
    • #3: Don’t Ignore Warnings
    • #4: Comment As You Go
    • #5: Always Use Parentheses
    • #6: Always Define Literals
    • #7: Never Repeat Yourself
  • CS-101
  • Python-101
  • Simple Tricks
  • Guestbook

The Hard-Core Coder

~ I can't stop writing code!

The Hard-Core Coder

Tag Archives: Python classes

Dual Numbers in Python

17 Monday Nov 2025

Posted by Wyrd Smythe in Interesting, Python

≈ 1 Comment

Tags

dual number, function derivative, Python classes, Python code, software design

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 →

Simple Python Tricks #16

21 Monday Jul 2025

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Python classes, Python code, Simple Tricks

Simple Tricks #10 was about Python classes with a focus on the __new__ and __init__ built-in methods plus how to use them when extending Python’s built-in list, tuple, and dict classes.

In this edition of Simple Tricks, we’ll look at a number of possibly actually useful subclasses of Python’s dict class. Specifically, a “ticket” class, a “list of files” class, and an INI file class.

Continue reading →

Simple Python Tricks #12

25 Monday Nov 2024

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Python classes, Python code, Python descriptors, Python properties, Simple Tricks

The last two Simple Tricks posts looked at subclasses of built-in Python classes, in particular the tuple class, as well as the built-in class methods Python supports for any user-defined class. [See Simple Tricks #10 and Simple Tricks #11.]

This time I narrow the focus to real and virtual object attributes, the “x”, “y”, “z” elements of our vector objects. Python offers many ways to implement these, depending (as always) on what you want.

Continue reading →

Simple Python Tricks #11

11 Monday Nov 2024

Posted by Wyrd Smythe in Python

≈ 2 Comments

Tags

Python classes, Python code, Simple Tricks

Last time we looked at subclassing the Python built-in classes tuple, list, and dict with a focus on the built-in __new__ and __init__ methods (and never forget to include __str__ and/or __repr__ in your user-defined classes).

This time Simple Tricks explores many of the other built-in methods that help you create richly featured Python-aware objects. Specifically, we’ll focus on subclassing tuple to create (immutable) vector objects. A basic understanding of object-oriented programming is assumed.

Continue reading →

Simple Python Tricks #10

28 Monday Oct 2024

Posted by Wyrd Smythe in Python

≈ 4 Comments

Tags

Python classes, Python code, Simple Tricks, sub-class

Last time, Simple Tricks looked at some built-in Python functions. This time, we look at three built-in Python container classes, tuple, list, and dict, with a focus on designing useful sub-classes based on them.

We’ll explore the built-in __new__ and __init__ methods in detail along with some of the other built-in methods that help you to create rich new types. [The reader is assumed to be familiar with the basics of object-oriented programming.]

Continue reading →

Follow The Hard-Core Coder on WordPress.com

The Posts

  • Python Tk Calculator App
  • Tk Windows in Python
  • Dual Numbers in Python
  • Python Decorators, more
  • Python Decorators, redux
  • Byte Multiplication Trick
  • Parsing Multipart Form Data
  • Simple Python Tricks #18
  • Simple Python Tricks #17
  • Simple Python Tricks #16

The Topics

  • Blog (4)
  • CS101 (37)
  • Fun (36)
  • Interesting (5)
  • Opinion (12)
  • Python (59)
  • Stories (15)

The Month

December 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Nov    

The Past

Posts

RSS Feed

Comments

RSS Feed

The Main Blog

Visit Logos con carne

Lots of wyrds... with meat!

The Author

Wyrd Smythe

Wyrd Smythe

The canonical fool on the hill watching the sunset and the rotation of the planet and thinking what he imagines are large thoughts.

View Full Profile →

Create a website or blog at WordPress.com

  • Subscribe Subscribed
    • The Hard-Core Coder
    • Already have a WordPress.com account? Log in now.
    • The Hard-Core Coder
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar