On StackOverflow, someone wanted to
print triangles in Python
in an M-shape.
Various clumsy solutions were offered.
Here’s mine which uses the left- and right-justification features of
str.format.
- "{0}+++{0}".format('Hello!') produces two copies of the zeroth argument to format
(here 'Hello!'), separated by three plusses: Hello!+++Hello!.
- "{:<4}".format('x') left-justifies 'x' in a 4-character field; i.e., 'x '.
- "{:>4}".format('x') right-justifies 'x' in a 4-character field; i.e., ' x'.
- "{:>{}}".format('x', width) right-justifies 'x' in a width-character field.
- 'ab' * 4 yields 4 copies of 'ab'; i.e., 'abababab'.
Putting them together:
.. code:: pycon
>>> WIDTH = 4
>>>
>>> for a in range(1, WIDTH+1):
... print("{0:<{1}}{0:>{1}}".format('*' * a, WIDTH))
...
* *
** **
***
…continue.
Title: Star Fall
Author: Cynthia Harrod-Eagles
Rating: ★ ★ ★ ★
Publisher: Severn House
Copyright: 2015
Pages: 256
Keywords: mystery, police procedural
Reading period: Nov 28–Dec 3, 2015
Rowland Egerton, star of a popular antiques TV show,
is found murdered in his London home.
When Detective Inspector Bill Slider and his team investigate,
they uncover sordid secrets unknown to the British public.
This was a witty and entertaining police procedural,
showing both the working and home lives of Slider and team.
Title: Grace of Kings
Author: Ken Liu
Rating: ★ ★ ★ ★
Publisher: Saga Press
Copyright: 2015
Pages: 614
Keywords: fantasy
Reading period: Oct 1–Dec 2, 2015
Loosely modeled on the rise of the Han dynasty,
Ken Liu’s fantasy tells us of two men who rise up to challenge the emperor.
Kuni Garu, the wily and wise one-time bandit, and
Mata Zyndu, the warrior scion of a deposed noble clan,
are friends initially but fall out.
The gods are at play in the affairs of men
and they take pleasure in causing trouble and strife.
I enjoyed the novel, but I disliked the pace at which Liu galloped through events.
More
When I upgraded my home and work MacBooks to
OS X 10.11 (El Capitan),
the single biggest annoyance for me was that my external keyboards,
all Microsoft Natural Keyboard 4000s,
no longer swapped the Alt & Windows key.
By default, when a PC keyboard is plugged into a Mac,
the Alt key,
which is immediately to the left of the spacebar,
is mapped to the Alt/Option key,
which is two keys left of the spacebar on a Mac keyboard.
And the Windows key,
which is two keys to the left of the spacebar on a PC keyboard,
is mapped to the Command key,
which is next to the spacebar on a Mac keyboard.
On a Mac, …continue.
I was debugging a filtering directory walker
(on which, more to follow)
and I was trying to figure out
the mysterious suffix that
fnmatch.translate
appends to its result,
\Z(?ms).
fnmatch.translate takes a Unix-style glob,
like *.py or test_*.py[cod],
and translates it character-by-character into a regular expression.
It then appends \Z(?ms).
Hence the latter glob becomes r'test\_.*\.py[cod]\Z(?ms)',
using Python’s raw string notation to avoid the
backslash plague.
Also, the ? wildcard character becomes the . regex special character,
while the * wildcard becomes the .* greedy regex.
A StackOverflow answer partially explains,
which set me on the right track.
(?ms) is equivalent to compiling the regex with re.MULTILINE | re.DOTALL.
The re.DOTALL modifier makes the . special character
match any character,
including newline;
normally, …continue.
Blogging has been on my mind lately,
as I’ve just set up an engineering blog at work.
I gave a speech about blogging earlier tonight
to my club, Freely Speaking Toastmasters.
I no longer write speeches beforehand;
I extemporized my speech from a
mindmap
that I had prepared yesterday.
This post is a more coherent and expanded rendition of my points.
As Toastmasters, we give speeches about topics that interest us,
when we want to share or inform or entertain.
A live, in-person speech reaches a direct audience at one point in time.
A written blog post can reach a much larger audience.
Toastmasters have something to say, whether in person or in print.
A blog can …continue.
[Previously published at the now defunct MetaBrite Dev Blog.]
At MetaBrite, we believe in the power of pair programming.
We find that pairing helps for collaboration on difficult tasks,
for exploring new areas, for knowledge transfer,
and for spurring each other to better solutions.
I find it to be fun, though it can also be exhausting.
It’s not ideal for all our work—there’s no value in tying up two developers on some rote task that both know well.
Last week, I rebuilt our primary pairing workstation.
In its previous incarnation, we had an account for each developer.
Each of us had set up some personal preferences in our own user …continue.
I’m doing some Python profiling
and I wanted to use the RunSnakeRun utility to view the profile data.
Unfortunately, that’s not straightforward on Mac OS X if you use a virtualenv,
and it’s even less easy if you’re using the Python
installed by the Homebrew (brew) package manager.
There are several problems:
- Installing wxPython on OS X 10.10.
This is the cross-platform GUI API toolkit used by RunSnakeRun.
- Getting wxPython installed in a virtualenv
- Running wxPython apps in a virtualenv on the Mac.
Installing wxPython
I downloaded wxPython3.0-osx-3.0.2.0-cocoa-py2.7.dmg,
released in November 2014.
If you open the DMG and attempt to run the PKG,
you will likely get a misleading error message from OS X:
“wxPython3.0-osx-cocoa-py2.7.pkg” is damaged and can’t be opened.
You should eject …continue.
Title: Hard Freeze
Author: Dan Simmons
Rating: ★ ★ ★ ★
Publisher: St. Martin’s/Minotaur
Copyright: 2002
Pages: 295
Keywords: crime, thriller, noir
Reading period: 27 May, 2015
Joe Kurtz is marked for death after the events of
Hardcase.
And a concert violinist is convinced that he just saw the man
who murdered his teenaged daughter 20 years earlier, who was thought dead.
More mayhem.
As I announced
a couple of weeks ago,
we’re off to Berlin for June and July.
We leave the house at 4:30am tomorrow to catch a 6:45am flight to Chicago
and thence via Dublin, arriving in Berlin at 10:30am on Tuesday.
There’s nothing like a deadline to focus the mind and make things happen.
We’ve been spring cleaning furiously for several weeks.
Frankly, it was long overdue.
The bedrooms and the offices were all badly in need of being reorganized.
My office used to scare me, it was such a mess.
It’s still far from perfect, but it’s much cleaner,
you can use the desk, and the remaining clutter is stacked into …continue.
Previous »
« Next