My DasBlog-based blog at http://www.georgevreilly.com/blog/
has been out of commission for months.
I've been meaning to replace it for a long time,
but I only just got around to making a serious effort,
as I realized that otherwise I would have no posts at all for 2014.
I received only a handful of complaints about its absence;
if there had been more, I would have fixed it sooner.
DasBlog is a fairly lightweight blogging engine that runs on ASP.NET.
It doesn't require a database,
but it does require the ability to write XML blogpost entries to the local filesystem.
That's a non-standard configuration for ASP.NET and IIS websites,
which inevitably causes …continue.
I've spent some time this evening profiling a Python application on Windows,
trying to find out why it was so much slower than on Mac or Linux.
The application is an in-house build tool which reads a number of config files,
then writes some output files.
Using the RunSnakeRun Python profile viewer on Windows,
two things immediately leapt out at me:
we were running os.stat a lot
and file.close was really expensive.
A quick test convinced me that we were stat-ing the same files over and over.
It was a combination of explicit checks and implicit code,
like os.walk calling os.path.isdir.
I wrote a little cache that memoizes the results,
which brought …continue.
I wrote up some lessons that I learned about
SQLAlchemy Sharding
at the Cozi Tech Blog.
Python has long had a string interpolation operator, %.
Python 2.6 and 3.0 introduced a new, richer set of string formatting operations.
See PEP 3101 for the rationale.
One trick that I liked with the old way of formatting was
to put the locals() dictionary or self.__dict__
on the right-hand side
>>> def stuff(a, b):
... c = a+b; d = a-b
... return "%(a)s, %(b)s, %(c)s, %(d)s" % locals()
...
>>> stuff(3, 17)
'3, 17, 20, -14'
It took me a few minutes to figure out how to do the equivalent with string.format:
use the ** syntax to unpack the dict into kwargs.
>>> class Person(object):
... def __init__(self, name, age):
...
…continue.
The Cozi Tech Blog needed some love,
so I wrote a post on augmenting Python's strftime.
Python has list comprehensions,
syntactic sugar for building lists from an expression.
>>> [2 * i for i in (2, 3, 5, 7, 11)]
[4, 6, 10, 14, 22]
This doesn't work so well when the comprehension expression
is itself a list: you end up with a list of lists.
>>> def gen():
... for l in [['a', 'b'], ['c'], ['d', 'e', 'f']]:
... yield l
...
>>> [l for l in gen()]
[['a', 'b'], ['c'], ['d', 'e', 'f']]
This is ugly. Here's one way to build a flattened list,
but it's less elegant than the comprehension.
>>> x = []
>>> for
…continue.
Eric and I attended Northwest Python Day 2009 today at the University of Washington.
There were about 50 people present, with a few out-of-town visitors from
Portland and Vancouver BC.
It was a mixed bag.
I found the afternoon sessions more interesting than the morning ones.
The morning talks started with a set of five-minute lightning talks, including:
- ctypes being used to crack open a raw binary file with arbitrary bit alignment.
- Werkzeug: a set of WSGI utilities. Debugger sounds particularly useful.
- BuildBot: Eric talked about using it for Continuous Integration and
how easy it was to configure and extend, compared to CruiseControl.NET.
Browser Interface, Local …continue.
At Cozi,
we're writing our new web services in Python (a story for another day).
I wrote up a few hard-won tips on using the Cheetah Template library
at the Cozi Tech Blog.
This week, I have written code in C#, C++, Managed C++, C, WiX, NAnt,
ActionScript, VBScript, JScript, cmd batch, NMake, HTML,
XSLT, and Ruby. And I will probably get some Python in before the weekend
is over. <boggle/>
Batchfile Wrapper
I've made some significant changes to my Python Batchfile Wrapper.
The main virtue of this wrapper is that it finds python.exe and
invokes it on the associated Python script,
ensuring that input redirection works.
I've also adapted py2bat to work with my wrapper.
I'm calling my version py2cmd.
Here's my latest batch file, which is shorter than its predecessor.
To use it, place it in the same directory as the Python script
you want to run and give it the same basename;
i.e., d:\some\path or other\example.cmd
will run d:\some\path or other\example.py.
@echo off
setlocal
set PythonExe=
set PythonExeFlags=-u
for %%i in (cmd bat exe) do (
for %%j in (python.%%i) do
…continue.
Previous »
« Next