Every so often, one of our Bamboo builds would break thus:
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 17] File exists: '/home/bamboo/.python-eggs'
The Python egg cache directory is currently set to:
/home/bamboo/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
This occurred while trying to make use of PyCrypto.
After a little research, I decided that instead of installing PyCrypto
as a zipped egg (as it does by default) into the …continue.
I did a clean install of OS X 10.10 on my home laptop a week ago.
I tried to launch PyCharm 4.0.4 on it today.
It immediately failed. Every time.
When I looked in the System Console, I saw:
1/25/15 7:46:00.557 PM pycharm[1160]: No matching VM found.
1/25/15 7:46:00.711 PM com.apple.xpc.launchd[1]: (com.jetbrains.pycharm.58252[1160]) Service exited with abnormal code: 1
The JetBrains website wasn't very helpful when I looked there.
In time, I found a StackOverflow answer that put me on the right track
(and reminded me that I had previously solved this problem about a year ago, at work).
PyCharm and some of the other JetBrains IDEs require JDK 1.6,
as …continue.
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.
Previous »
« Next