-
Recent Posts
- Workaround for flask/babel/sphinx bug on Python 3+
- enum in Python
- Python Decorators
- Unicode – the basics
- Python’s magic methods
- Gotcha — Mutable default arguments
- Unicode for dummies — Encoding
- How to post source code on WordPress
- Python3 pickling
- Yet Another Lambda Tutorial
- Read-Ahead and Python Generators
- In Java, what is the difference between an abstract class and an interface?
- Newline conversion in Python 3
- Why import star is a bad idea
- Learning Subversion: the mystery of .svn
- How to fix a programmable Northgate keyboard
- Northgate keyboard repair
- An alternative to string interpolation
- A Globals Module pattern
- An Arguments Container pattern
- A Globals Class pattern for Python
- How to open a web browser from Python
- Command-line syntax: some basic concepts
- Unicode for dummies – just use UTF-8
- Unicode Beginners Introduction for Dummies Made Simple
- Multiple constructors in a Python class
- How do I reverse a string in Python 3?
- What’s wrong with use cases?
- Python Packages
- Diagram arrangements
- Python & Java: A Side-by-Side Comparison
- Static vs. dynamic typing of programming languages
- Debugging in Python
- Introduction to Python Decorators
- Gotcha — forgetting parentheses
- Gotcha — backslashes in Windows filenames
- Gotcha — backslashes are escape characters
- Python Gotchas
Categories
- Decorators (2)
- Java and Python (3)
- Keyboards (2)
- Miscellaneous (2)
- Moving to Python 3 (3)
- Python & JSD (1)
- Python debugger (1)
- Python features (9)
- Python Globals (3)
- Python gotchas (5)
- Software Development (2)
- Subversion (1)
- Unicode (4)
Author Archives: Steve Ferg
Workaround for flask/babel/sphinx bug on Python 3+
I’m using Python 3.4 on Windows. Recently I tried to install and use Sphinx. When I did, I encountered an error that ended with the string an integer is required (got type str) Googling that string, I found an explanation … Continue reading
Posted in Python features
Comments Off on Workaround for flask/babel/sphinx bug on Python 3+
enum in Python
Recently I was reading a post by Eli Bendersky (one of my favorite bloggers) and I ran across a sentence in which Eli says “It’s a shame Python still doesn’t have a functional enum type, isn’t it?” The comment startled … Continue reading
Posted in Python features
8 Comments
Python Decorators
In August 2009, I wrote a post titled Introduction to Python Decorators. It was an attempt to explain Python decorators in a way that I (and I hoped, others) could grok. Recently I had occasion to re-read that post. It … Continue reading
Posted in Decorators
32 Comments
Unicode – the basics
An introduction to the basics of Unicode, distilled from several earlier posts. In the interests of presenting the big picture, I have painted with a broad brush — large areas are summarized; nits are not picked; hairs are not split; … Continue reading
Posted in Unicode
3 Comments
Python’s magic methods
Here are some links to documentation of Python’s magic methods, aka special methods, aka “dunder” (double underscore) methods. Rafe Kettler’s A Guide to Python’s Magic Methods ::—> http://www.rafekettler.com/magicmethods.html Michael Foord’s chapter on Python Magic Methods from this book IronPython in … Continue reading
Posted in Python features
2 Comments
Gotcha — Mutable default arguments
Goto start of series Note: examples are coded in Python 2.x, but the basic point of the post applies to all versions of Python. There’s a Python gotcha that bites everybody as they learn Python. In fact, I think it … Continue reading
Posted in Python gotchas
6 Comments
Unicode for dummies — Encoding
Another entry in an irregular series of posts about Unicode. Typos fixed 2012-02-22. Thanks Anonymous, and Clinton, for reporting the typos. This is a story about encoding and decoding, with a minor subplot involving Unicode. As our story begins — … Continue reading
Posted in Unicode
5 Comments
How to post source code on WordPress
This post is for folks who blog about Python (or any programming language for that matter) on WordPress. Updated 2011-11-09 to make it easier to copy-and-paste the [sourcecode] template. My topic today is How to post source code on WordPress. … Continue reading
Posted in Miscellaneous
23 Comments
Python3 pickling
Recently I was converting some old Python2 code to Python3 and I ran across a problem pickling and unpickling. I guess I would say it wasn’t a major problem because I found the solution fairly quickly with a bit of … Continue reading
Posted in Moving to Python 3
Comments Off on Python3 pickling
Yet Another Lambda Tutorial
There are a lot of tutorials[1] for Python’s lambda out there. A very helpful one is Mike Driscoll’s discussion of lambda on the Mouse vs Python blog. Mike’s discussion is excellent: clear, straight-forward, with useful illustrative examples. It helped me … Continue reading
Posted in Python features
17 Comments
Read-Ahead and Python Generators
One of the early classics of program design is Michael Jackson’s Principles of Program Design (1975), which introduced (what later came to be known as) JSP: Jackson Structured Programming. Back in the 1970’s, most business application programs did their work … Continue reading
Posted in Python & JSD
7 Comments
In Java, what is the difference between an abstract class and an interface?
This post is about Java, and has nothing to do with Python. I’ve posted it here so that it can be available to other folks who might find it useful. (And because I don’t have a Java blog!) In Java, what … Continue reading
Posted in Java and Python
14 Comments
Newline conversion in Python 3
I use Python on both Windows and Unix. Occasionally when running on Windows I need to read in a file containing Windows newlines and write it out with Unix/Linux newlines. And sometimes when running on Unix, I need to run … Continue reading
Posted in Moving to Python 3
7 Comments
Why import star is a bad idea
When I was learning Python, I of course read the usual warnings. They told me: You can do from something_or_other import * but don’t do it. Importing star (asterisk, everything) is a Python Worst Practice. Don’t “import star”! But I … Continue reading
Posted in Python features
11 Comments
Learning Subversion: the mystery of .svn
If you are googling for “Subversion command line tutorial introduction for beginners”, read this first! This is for all Subversion newbies. After using PVCS for many years, our office recently started moving to Subversion. Which means that recently I started … Continue reading
Posted in Subversion
11 Comments
How to fix a programmable Northgate keyboard
After my earlier post about Northgate keyboard repair it occurred to me that this information might be useful. I don’t think it can be found anywhere else on the Web. Note that in the following slideshow (showing the repair of … Continue reading
Posted in Keyboards
5 Comments
Northgate keyboard repair
The best computer keyboards ever made (even when compared to the original IBM model M keyboards) were the Northgate Omnikey keyboards. They were heavy keyboards built like tanks, featuring buckling spring key-switches notable for their distinctive clicking as you typed. These were real … Continue reading
Posted in Keyboards
14 Comments
An alternative to string interpolation
I sort of like this. # ugly msg = “I found %s files in %s directories” % (filecount,foldercount) # better def Str(*args): return “”.join(str(x) for x in args) : : msg = Str(“I found “, filecount, ” files in “, … Continue reading
Posted in Python features
15 Comments
A Globals Module pattern
Two comments on my recent posts on a Globals Class pattern for Python and an Arguments Container pattern reminded me that there is one more container for globals that is worth noting: the module. The idea is a simple one. You … Continue reading
Posted in Python Globals
Comments Off on A Globals Module pattern
An Arguments Container pattern
In a comment on my earlier post A Globals Class pattern for Python, Mike Müller wrote “No need for globals. Just explicitly pass your container. In my opinion this is much easier to understand.” Mike’s comment led me to some … Continue reading
Posted in Python Globals
5 Comments
A Globals Class pattern for Python
I’ve gradually been evolving a technique of coding in which I put module globals in a class. Recently I stumbled across Norman Matloff’s Python tutorial in which he recommends doing exactly the same thing, and it dawned on me that … Continue reading
Posted in Python Globals
8 Comments
How to open a web browser from Python
This goes under the Tips and Tricks category. Also under Stuff I wish I had known about a long time ago. The trick is in the standard library, in the webbrowser module. “”” For documentation of the webbrowser module, see … Continue reading
Posted in Python features
4 Comments
Command-line syntax: some basic concepts
I’ve been reading about parsers for command-line arguments lately, for example Plac. And, as Michele Simionato says: There is no want of command line arguments parsers in the Python world. The standard library alone contains three different modules: getopt (from … Continue reading
Posted in Miscellaneous
4 Comments
Unicode for dummies – just use UTF-8
Revised 2012-03-18 — fixed a bad link, and removed an incorrect statement about the origin of the terms “big-endian” and “little-endian”. Commenting on my previous post about Unicode, an anonymous commentator noted that the usage of the BOM [the Unicode … Continue reading
Posted in Unicode
9 Comments
Unicode Beginners Introduction for Dummies Made Simple
I’ve been trying to grok Unicode, and it hasn’t been easy. But today, I finally got it. And, as it turns out, the basics of Unicode aren’t too difficult. The problems that I’ve been having turn out not to be … Continue reading
Posted in Unicode
12 Comments
Multiple constructors in a Python class
In addition to working with Python, I also work with Java quite a lot. When coding in Python, I occasionally encounter situations in which I wish I could code multiple constructors (with different signatures) for a class, the way you can … Continue reading
Posted in Python features
6 Comments
How do I reverse a string in Python 3?
With the improved support for Unicode in Python3, more and more folks will be working with languages (Arabic, Hebrew, etc.) that read right-to-left rather than left-to-right. So more and more folks will have a need to reverse a string. Unfortunately, … Continue reading
Posted in Moving to Python 3
12 Comments
What’s wrong with use cases?
I originally wrote this in 2002, when Use Cases seemed to be all the rage. I thought I would republish it here because the Use Case Approach — although now operating under a variety of new names — still seems … Continue reading
Python Packages
I’ve avoided putting my Python modules into packages. That’s because (like a lot of other folks) I don’t really understand how to create a package. And that’s because (probably like a lot of other folks) I’m too time-constrained and over-worked … Continue reading
Posted in Python features
6 Comments
Diagram arrangements
Aesthetics matters! For a number of years I did quite a lot of teaching — computer systems analysis and design, and also data modeling and database design. During the classes the students and I constructed a lot of diagrams of … Continue reading