text: Python Programming, news on the Voidspace Python Projects and all things techie.
  New Home for Firedrop2 SVN
  Firedrop2 has a new subversion repository and Trac site.
  Many thanks to the folks at Python-hosting.com for this great service.
  The repository has the 0.1.3 release in a tag.
  On the trunk is what is about to become Version 0.2.0. Thanks to a lot of hard work by Stewart Midwinter, this next release will include :
  - Support for markdown markup
  - A fix for Mac OS X support
  - A switch to using ConfigObj for the config files
  - Creating a blog will automatically open it in the editor
  - Sensible error message if you try to create a new entry without a blog opened
  - You can specify a default site to be opened when you start Firedrop
  - An improved Styles menu
  And possibly other things I've forgotten. When we do the release I'll make sure we have a full list of all the changes.
  Note
  The version on the trunk is only suitable for new blogs. It doesn't yet have a way to migrate existing blogs to the new build.ini format. That will be added shortly.
  Because I want to keep all the developer discussion off the Firedrop2 Users List, I've created a new developers list on the Sourceforge Project :
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-03-03 12:13:19 | |
  Categories: Projects, Python
  Wingware IDE
  One of the companies I have approached in looking for potential sponsors for Voidspace is Wingware. As a small company they didn't feel able to take me up on it, but they have given me a free license for their IDE.
  This is very generous of them, thanks Stefan.
  Up until now I've been using SPE which I've been very happy with. I'm used to the feel of SPE, so Wing feels a bit 'unfamiliar'. It's certainly more polished (which is only to be expected), but whether it offers me any tangible benefits I'm not yet decided on.
  Scouting round the web it seems that the Wing debugger is very good. I'm afraid my usual method of debugging usually consists of liberal use of print statements. I'm not alone :
  On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.
  So I may not gain a lot of advantage from this part of Wing. One thing I do like is that it has back and forward arrows (like my favourite text editor, Ultraedit). This allows you to jump backwards and forwards between the positions you have been editing in your code. This is great if you need to go and copy a piece of code from elsewhere in your file, and then jump back to where you need to insert it into.
  Anyway, the jury is still out as to whether I switch to using Wing for my day to day editing, I will certainly continue to use SPE wherever I use Movable Python.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-03-03 12:13:12 | |
  Categories: Python, Tools
  Struggling with Python
  It's been around a while, but it's still good.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-03-03 11:27:40 | |
  imp.find_module with py2exe
  As I mentioned previously there is a problem with imp.find_module and Movable Python.
  This is because the imp module doesn't understand the PEP302 importhook (which zipimport uses). That means that any code which uses imp.find_module will probably fail for programs packaged using py2exe.
  I've hacked a workaround which 'monkey patches' imp to get round this. It's a hack because it uses zipmport to retrieve the bytecode object (if the module requested lives in library.zip) and then turns this back into a bytecode file. It has to create a real temporary file to do this, because imp.load_module won't accept a file like object as an argument. This means there is a cleanup function which deletes any temporary files created. You should call this at the end of your program.
  If anyone has a better way, I'm all ears [1].
  To use this code :
  Save it as a module called zip_imp.py. Then in your program do :
  # .. code which possibly calls imp.find_module
  cleanup()
  The initial import patches the imp module. If your zip file isn't the first path on sys.path that ends with .zip, then you will need to set zip_imp._zip_file to the path to your zip file.
  import os
  import imp
  import marshal
  import tempfile
  from zipimport import zipimporter, ZipImportError
  """
  A module that patches ``imp.find_module`` to work from within py2exe.
  You must call ``import zip_imp`` *before* importing imp.
  On finishing you must call ``zip_imp.cleanup()``. This deletes any temporary
  files created.
  This will only work if you have a zip file on ``sys.path`.
  """
  __all__ = ['cleanup']
  _zip_file = None
  for entry in sys.path:
  if entry.endswith('.zip'):
  _zip_file = entry
  break
  _file_array = []
  imp._find_module = imp.find_module
  def _find_module(name, path=None):
  try:
  return imp._find_module(name, path)
  except ImportError:
  if _zip_file is None:
  raise ImportError
  z = zipimporter(_zip_file)
  try:
  code = z.get_code(name)
  except ZipImportError:
  raise ImportError('Failed to find module: %s' % name)
  mod = _make_pyc(code)
  mod_names = [_zip_file] + name.split('.')
  mod_names[-1] += '.pyc'
  pathname = os.path.join(*mod_names)
  description = ('.pyc', 'rb', imp.PY_COMPILED)
  return (mod, pathname, description)
  def _make_pyc(code):
  """
  Turn a bytecode object back into an open file representing a '.pyc' file.
  Uses the spec laid out at :
  It uses the magic number from the ``imp`` module, and four null bytes to
  represent the modification time of the bytecode file.
  """
  n = tempfile.mktemp()
  t = open(n, 'w+b')
  t.write(imp.get_magic() + chr(0)*4 + marshal.dumps(code))
  t.seek(0)
  _file_array.append((n, t))
  return t
  imp.find_module = _find_module
  def cleanup():
  """Clean up any temporary files created when using ``load_module``."""
  for name, file_obj in _file_array:
  # calling close on an already closed file doesn't hurt
  file_obj.close()
  os.remove(name)
  if __name__ == '__main__':
  if not hasattr(sys, 'frozen'):
  print 'This test only works from *inside* Movable Python or a',
  print 'program frozen with py2exe.'
  sys.exit()
  #
  name = 'Cookie'
  try:
  file, pathname, description = imp.find_module(name)
  except ImportError:
  print 'Failed to ``find_module``.'
  else:
  print file, pathname, description
  print '``find_module`` succeeded.'
  m = imp.load_module(name, file, pathname, description)
  print "``load_module`` succeeded."
  file.close()
  #
  print m
  print m.Cookie
  #
  cleanup()
  This code (or something like it) will be included in the next release of Movable Python [2].
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-03-01 13:23:29 | |
  Categories: Projects, Python, Hacking
  Nanagram 1.4 Released
  Nanagram 1.4 is now available.
  This is a Shareware program, and there is a free demo version available. The source code to Nanagram 1.3 is still freely available, under the Shareware License.
  On the Voidspace Shop you will find windows installers and executable versions of both the full program and the free demo. The free demo has a smaller dictionary and a few less features, but is still worth playing around with. The full version costs £4.99.
  What is Nanagram ?
  Nanagram is an anagram maker. Astound and annoy your friends by discovering what silly anagrams can be made from their names. It can also be used to help solve crossword puzzles. Nanagram has a friendly interface and a host of features.
  What's New in 1.4 ?
  - Improved the GUI.
  - Sped up the anagram finding by around 20%.
  - Now built with Python 2.4 and psyco 1.5 for even more speed.
  - Added the progress bar.
  - Added the option to include common short words.
  - Optimised sorting the results.
  - We can now find anagrams where a word fits more than once into the original phrase.
  Plus various other minor changes and improvements.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-28 11:17:57 | |
  Categories: Projects, Python
  Voidspace Shareware Mailing List
  To go along with the programs I'm releasing as Shareware, there is (another) new mailing list. This is for support, discussion, bug reports and feature requests.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-28 11:07:18 | |
  IPython, matplotlib & Movable Python
  I can confirm that matplotlib works with IPython under Movable Python.
  This gives you the interactive features of matplotlib with Movable Python.
  To get this to work you need ipython.py from the IPython distribution. You then run :
  movpy ipython.py -pylab -ipythondir lib/
  This assumes you run the command at the command line, from the same directory as movpy.exe. It does still writes .matplotlib\ttffont.cache to the %home% directory. There is probably a way of telling matplotlib not to do this though.
  Thanks to Jens Spille for checking this for me.
  Python 2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.7.1.fix]: t = arange(1,50) In [2]: y=sin(t) In [3]: plot(t,y) Out[3]: [<matplotlib.lines.Line2D instance at 0x01884A58>]
  Movable Python as graphical caluclator.
  The next release of Movable Python will let you run movpy - -pylab.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-28 10:53:44 | |
  Categories: Python, Projects
  Voidspace Shareware
  I've just launched the Voidspace Shareware Page.
  This is where the programs I release as shareware will be available from. Currently this is :
  Another new program release will follow in the next day or so, with more to come...
  For most of these projects free demo versions will be available, and for some of them the Python source code will be available under a Shared Source Type license.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-27 15:56:54 | |
  Categories: Python, Work, Projects
  Movable Python & WebWare
  I have a (potential) customer who wants to use WebWare with Movable Python. He said that he couldn't get WebWare started, and he would email the details when he got home.
  I'm afraid my curiosity got the better of me, so I downloaded to see if I could find the problem. Yes, I could see the problem, it failed to start [1].
  The error message was a slightly obscure one about a file descriptor being needed to close a file. Tracking the bug through the code (and shutting down some error handling that masked the real nature of the problem), revealed the following :
  (file, pathname, description) = imp.find_module('Cookie', path)
  CookieEngine = imp.load_module('Cookie', file, pathname, description)
  except:
  if file:
  file.close()
  This is from line 25 in WebKit/Cookie.py. The problem is that imp.find_module wants to return an open file object. For Movable Python (and indeed any application created by py2exe) that fails because the real Cookie module is contained within library.zip.
  They have also wrapped two calls in the try: ... except: block. When the find_module call fails, the name file (shadowing a builtin guys) isn't bound. Calling file.close() then raises an obscure error because the file type expects a descriptor for that call.
  What they're doing here is attempting to dynamically load the standard library Cookie module if it's available. This allows them to support Python versions < 2.2. (Is anyone really doing that ?)
  A temporary solution is to change line 10 of Cookie.py to :
  This gets round the problem and WebWare starts fine. For the next version of Movable Python I'll attempt to monkey patch imp.load_module so that it does something sensible (possibly extracting the file and returning a StringIO instance).
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-27 15:33:03 | |
  Categories: Projects, Python, Hacking
  matplotlib and Movable Python
  I've managed to get matplotlib working for Movable Python.
  Note
  This means that it must be possible to get matplotlib working with py2exe.
  There is a download linked to at the bottom of this post which contains the files to use matplotlib with Python 2.4.2. They should work with Movable Python or a normal Python installation.
  This means that numarray also works.
  Unfortunately it looks like I'm going to have to do a bit of work (although probably not much) to get IPython working in pylab mode. It should currently be possible to follow the matplotlib interactive instructions and use it from a PyCrust shell.
  The matplotlib folks didn't make my life easy when it came to getting this working. I was installing it for Python 2.4 on Windows. The installation instructions say :
  For standard python installations, you will also need to install either Numeric or numarray in addition to the matplotlib installer. matplotlib provides installers for Numeric and numarray users. It is important that you pick the matplotlib installer that corresponds to your array package. Ie, if you mostly work with numarray arrays, use the matplotlib numarray installer. matplotlib has a numerix setting in the matplotlib rc file (which by default resides in c:\python23\share\matplotlitb\matplotlibrc) and you should make sure this setting corresponds to your preferred array package.
  So I have to choose numeric or numarray and pick the right installer for matplotlib ? Sounds easy enough.
  So you go to download matplotlib, and discover that only one installer is available for Windows. It doesn't mention numeric or numarray at all. Oh well, my user has specified numarray, so I fetch that as well and install.
  I run one of the example programs and it complains that it can't find numeric ! Maybe the only version they offer now is for numeric, so I look for numeric and discover that it's now called numpy and that installing that results in the same error.
  Anyway - to cut a sadly longer story short, I eventually work out that the windows installer for matplotlib hasn't created a matplotlibrc file. I copy the one from here to C:\Documents and Settings\$USERNAME$\.maplotlib. Some progress - now it's complaining about an ImportError when looking for a module called gobject, which is part of GTK the default backend for matplotlib.
  I edited matplotlibrc :
  - I changed the default backend to TkAgg
  - I set numerix to numarray
  The examples now work, albeit with a host of warnings.
  If you want to use matplotlib with Movable Python (or just want to save yourself some of these traumas with Python 2.4 on Windows) then you can download the following file :
  matplotlib.zip (8mb)
  It contains three directories and a single Python file. These should all be placed in your movpy/lib/ directory (or site-packages for normal Python). The matplotlib directory contains an examples sub-directory.
  For the next version of Movable Python I will see if I can get ipython -pylab working. I don't foresee that being too difficult. I may need to work out how to specify a simpler location for the matplotlibrc file though.
  Like this post? Digg it or Del.icio.us it.
  Posted by Fuzzyman on 2006-02-25 10:57:03 | |
  Categories: Python, Projects
  Archives
  This work is licensed under a Creative Commons Attribution-Share Alike 2.0 License.
  Counter...