• Home
  • About
    • About The Coder
    • Language List
  • The Rules
    • Rule #1: Clarity Trumps Everything
    • Rule #2: Source Code is for Humans
    • Rule #3: Don’t Ignore Warnings
    • Rule #4: Comment As You Go!
    • Rule #5: Always Use Parentheses
  • CS-101
  • Python-101
  • Guestbook

The Hard-Core Coder

~ I can't stop writing code!

The Hard-Core Coder

Tag Archives: Python 101

Python String Translate

13 Thursday Oct 2022

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

Python 101, Python code

Python str instances have many useful methods. I use strip, split, startswith, and others, quite a lot, for instance. One method I haven’t had reason to use so far is translate. It takes a dictionary argument and uses it to map the existing string to a new string.

It’s flexible and useful, so it’s worth knowing how to use.

Continue reading →

Loving the Lambda

15 Saturday Jan 2022

Posted by Wyrd Smythe in Python

≈ 3 Comments

Tags

computer code, program, Python 101, Python code, Python lambda

One part of Python I especially appreciate is lambda functions. While I’ve never pursued functional programming, I do like many things about it, particularly the notion of functions as native data objects. Programming with functional objects opens new vistas. Most languages handle it one way or another, but languages make it natural.

Python’s lambda is such a facility, and I use it often. This week I finally got around to writing a lambda function I’ve been meaning to for a long time, and it’s my new favorite. I thought I’d share it along with some of my other “one-liners”…

Continue reading →

Python Tokenize

03 Friday Dec 2021

Posted by Wyrd Smythe in Python

≈ 1 Comment

Tags

HTML, Python 101, Python code

Recently I thought to myself, “Hey self,… Although I’ve never looked into them, I know Python has tools for parsing Python code. I wonder if they might make generating syntax-highlighted HTML pages of Python scripts pretty easy?”

I found the help page for the tokenize module, and the introduction says it’s “useful for implementing ‘pretty-printers,’ including colorizers for on-screen displays.” That sounds like a strong yes.

Continue reading →

Python Generators, part 3

24 Wednesday Nov 2021

Posted by Wyrd Smythe in Python

≈ 3 Comments

Tags

Python 101, Python code, Python generator

In the last two posts I’ve explored Python generator functions. The first post went over the basics and showed how they return an iterable object usable in for-loops and list constructors. The second post explored how generator functions work in more detail.

This time I’ll wrap it up with some examples that are a bit more involved. If Python generators were a mystery before these three posts, I hope you feel more comfortable with them after!

Continue reading →

Python Generators, part 2

23 Tuesday Nov 2021

Posted by Wyrd Smythe in Python

≈ 4 Comments

Tags

Collatz conjecture, Python 101, Python code, Python generator

Last time I began exploring Python generator functions. I mostly covered their basic function as iterables, and why they’re good in for-loops. They’re also good for infinite lists. Much of their value lies in how they defer processing an item until it is actually asked for.

This time I’ll dig into the send method, which allows sending messages to a running generator. I’ll also introduce the yield from statement, which allows us to wrap a generator with another function that also acts like a generator.

Continue reading →

Python Generators, part 1

22 Monday Nov 2021

Posted by Wyrd Smythe in Python

≈ 5 Comments

Tags

Python 101, Python code, Python generator

Python has a feature called a generator — it’s a way of writing a function that allows that function to trade control back and forth with a calling function. It’s not something one needs often, but it can very useful in certain situations.

Create a Python generator, firstly, in using yield instead of return and, secondly, by designing the function a little differently from one that generates and then returns a list of items.

Continue reading →

My Python App Framework

03 Saturday Oct 2020

Posted by Wyrd Smythe in Python

≈ Leave a comment

Tags

computer code, Python 101, Python code

For me, Python modules seem to divide into two basic classes: library modules and application modules. The former contain basic building blocks, but the latter has top-level routines the operating system invokes when it runs the application.

Today I thought I’d post about the application framework I use for all apps.

Continue reading →

Python Decorators, part 2

25 Saturday Apr 2020

Posted by Wyrd Smythe in CS101, Python

≈ Leave a comment

Tags

Aspect-Oriented Programming, computer language, programming language, Python 101, Python code, Python decorator

Last time I began exploring Python decorators, which are a way of having one function “wrap” another function. Because the wrapper has access to both the input parameters and the return value, it can modify these values (unbeknownst to the inner function).

This time I pick up where I left off by exploring decorators modifying return values, decorators that take parameters, and decorators in classes.

Continue reading →

Python Decorators, part 1

24 Friday Apr 2020

Posted by Wyrd Smythe in CS101, Python

≈ 1 Comment

Tags

Aspect-Oriented Programming, Python 101, Python code, Python decorator

I’ve been playing around with what Python calls decorators. They’re a built-in way of implementing Aspect-Oriented Programming techniques in Python. In fact, they’re quite powerful.

Since they aren’t a common language feature, they can be a little confusing at first, so I thought I’d try my hand at laying out how they work.

Continue reading →

Follow The Hard-Core Coder on WordPress.com

The Posts

  • Python String Translate
  • The Last Bug
  • Regular Expressions
  • Bits Bytes Chips Clocks
  • Loving the Lambda
  • Failure Tales
  • Naming Things (redux)
  • Calculating Entropy (in Python)
  • Building a Turing Machine
  • Python Tokenize

The Topics

  • Blog (4)
  • CS101 (35)
  • Fun (27)
  • Interesting (1)
  • Opinion (12)
  • Python (24)
  • Stories (15)

The Month

March 2023
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Oct    

The Past

Posts

RSS Feed

Comments

RSS Feed

Enter your email address to follow The Hard-Core Coder and get email when there is a new post.

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

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