Category Archives: Python features

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

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’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

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

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

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

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