• 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: Simple Tricks

Simple Python Tricks #18

25 Monday Aug 2025

Posted by Wyrd Smythe in Fun, Python

≈ 2 Comments

Tags

Simple Tricks, text

Recently I found myself dividing my attention between watching the Minnesota Twins lose yet another ballgame and goofing around with an idea that popped into my head for no reason I can name.

The idea turned out better than imagined in terms of capability given its design simplicity, so I thought I’d document it here. It’s not super useful as is, but those relatively new to Python might find it educational or otherwise helpful.

Continue reading →

Simple Python Tricks #17

18 Monday Aug 2025

Posted by Wyrd Smythe in Python

≈ 3 Comments

Tags

Python code, Simple Tricks, ZIP files

This edition of Simple Tricks contains a random collection of bits and pieces. First, some cute bits from the interweb, then some more-or-less one-off bits I whipped up for a project and which were just barely useful enough to keep. (If for no other reason than to publish them here.)

I’ll end with a pair of simple Python functions, one to list the contents of an existing ZIP file, and one to create a new one from files in a subdirectory. The latter can be the basis for a more sophisticated archive function.

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 #15

31 Monday Mar 2025

Posted by Wyrd Smythe in Python

≈ 2 Comments

Tags

format method, format strings, Python code, regular expressions, Simple Tricks, str.translate, upside down characters

The political situation in the USA has dampened my mood and crashed my interest in this Simple Tricks series, but in hope of getting at least one post out this month (and on the very last day, no less), I’m going to revisit two topics I’ve written about before.

Back in Issue #8 of this series, I wrote about formatted output (to screen or file), especially using format strings (“f-strings”) and the format function and built-in method. In this issue, I’ll revisit the latter for a more sophisticated example. I also have some goodies for the str.translate method.

Continue reading →

Simple Python Tricks #14

17 Monday Feb 2025

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

comma sequence, Python code, Simple Tricks

This post was meant to be the final edition of Simple Tricks in 2024. My every-other-Monday schedule had it slotted for December 23rd. But I came down with a respiratory virus on the 22nd. The post wasn’t complete at that point, so I pushed publication to the following Monday, the 30th, but I was sick until well into the new year.

I ended up taking January off from the web (and computers in general), and it’s not until now that I’ve caught up with myself. In any event, I’m not sure how many more of these Simple Tricks posts I’ll do, but here’s one more.
Continue reading →

Simple Python Tricks #13

09 Monday Dec 2024

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Monty Hall problem, Python code, Simple Tricks, tail recursion

The last few posts in this Simple Tricks series were perhaps a bit less than simple, so this month, here at the end of the year, I’m going to take it easy and enjoy the season. (I hope you are doing so as well!)

I’ve put together a random grab bag of little bits and pieces of Python. Nothing too complicated. And in all honesty, probably nothing terribly interesting or that useful, either. But you may find some of the approaches helpful.

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 →

Simple Python Tricks #9

14 Monday Oct 2024

Posted by Wyrd Smythe in Python

≈ 3 Comments

Tags

Python code, Simple Tricks

For many, fall means back to school, so for this blog I thought I’d return to Simple Tricks in Python. Fall also means Halloween for many, so hopefully these tricks will be treats, even if they do involve some very basic Python.

In this post, I explore some of Python’s more interesting and useful built-in functions, such as enumerate, sorted, reversed, map, and filter.

Continue reading →

← Older posts
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