Python Programming, news on the Voidspace Python Projects and all things techie.
Well, I'm sitting in the first keynote of PyCon 2007. The OLPC folks are doing some extremely interesting stuff. (Yes I'm blogging - and yes I'm listening and yes there is a lot of Python in OLPC.)
I need to wait until the end of the talk to find out when we're going to be allowed to buy them...
We arrived yesterday. Entry into the US was straightforward (phew). We were very tired (7 or 8 hour time difference) but we still managed to have some very interesting chats with other Pythoneers.
We also did a practise run through of our talk. We're still over time and we want to leave time for questions, so we've cut a few slides.
I have uploaded a copy of the talk to the PyCon site - but this is the 'full' talk (with notes, so hopefully it is a good reference), the actual talk will be a bit shorter.
As soon as I have a semi-stable version, I will upload it to Voidspace and post the URL here.
Now that the talk is over, let me add a few wows to the talk about OLPC. Their vision is incredible, it is about providing a learning tool to millions of children over the next few year. Their hardware is astonishing (lots of revolutions in battery technology, LCD technology, new chips and so on and so on). Their software stack is also amazing. Running on a system with 128mb of RAM and a 512mb NAND flash RAM disk rather than a harddrive. The talk included a rant about how software is growing bigger and slower at a faster rate than computers are getting faster and bigger. Modern computers take longer to boot-up than computers from five years ago.
More scary than any of these facts though is that part of the teaching vision is introducing kids to programming through these devices. There is a 'view source' button which will allow kids to see the source of programs they are running (and change them - that's why using an interpreted language is so important to them). So their vision is to introduce 100 million children to Python over the next few years... comp.lang.python could get pretty crowded.
PyCon Talk: First Hurdle Cleared
Today Andrzej and I had a practise run of our PyCon talk in front of the Resolver developers. Definitely the most hostile audience we will ever face.
It went very well. It was too long, but we know which bits to cut down and they gave us some very useful feedback. Thanks guys. Hopefully we will have another opportunity to have a practise run at the London Python Meetup on Wednesday.
I don't think we'll be giving out handouts. There are nearly thirty slides (don't worry - a lot of them can be skipped over during the talk), and with the notes it makes sixteen pages when the HTML is printed.
I'd like to put the talk up on my website, but I don't want to spoil the talk for anyone (or give them an excuse not to come). I don't see any of the other talk material available yet. What's the score here ?
I haven't been able to edit the talk summary, but I'd like to clarify the aims of the talk  :
- To demonstrate the breadth of Windows Forms
- To show you how to get started creating a basic Winforms application
- To provide examples of using a few specific controls
- To equip you to read the Microsoft documentation (MSDN) for other controls
Along with this we will discuss (briefly) why you might (or might not) want to use IronPython, we'll also encounter and explain some .NET terminology along the way. The talk will be illustrated with code snippets from the Tabbed Image Viewer, which of course will be shown in action.
|||First bugfix release out already. The path to the image files for the dialog needed to be absolute. It looks like using the open file dialog changes the current directory. WTF !?!? I need to persuade Andrzej that we need some tests...|
|||Talk number six, currently scheduled for first thing (!) Sunday morning.|
Tabbed Image Viewer
To support our talk on Developing with IronPython & Windows Forms, at PyCon, Andrzej and I (along with the help of our esteemed colleague Christian Muirhead) have created an example application. The result :
You can either download the latest release (with pre-built executable and DLL for Windows)  or use subversion.
This project demonstrates Windows Forms, using a variety of controls in 18k of source code, including a really funky about dialog.
There is also source C# illustrating creating a custom executable by embedding the IronPython engine. It also shows creating a class in C# and accessing it from IronPython.
The actual application views multiple images inside tabpages in a tabcontrol. In can load images in several formats and allows you to resave them in a different format. It has two view modes for images, a menu, context menu and toolbar and can copy images to the clipboard.
Most of the code is pretty straightforward. There is one part of voodoo magic in there, which implements a nice feature. This is everything associated with the SetClipboardViewer which uses the win32api (so Windows only for this feature, sorry). When an image is set on the clipboard, it is automatically pasted into a new tab in the image viewer.
This has kind of 'grown organically' in the last week, so the code needs refactoring, but its not too bad. If you have any questions about the code, feel free to ask Andrzej.
My favourite feature is the about dialog. Move the mouse over our names.
Tabbed Image Viewer does run under Mono (tested with 1.2.3 on Windows).
There are a few issues on Mono, the about dialog layout is screwed, the transparent color of the icons isn't recognised and a couple of other minor quirks . Patches accepted.
The one major thing that needs fixing is that we should have a 'preserve aspect ratio' view mode, rather than using the StetchImage size mode. Other than that we will probably just fix bugs and clean up the code.
|||There is some example C# as part of the project, but it isn't needed to run the application.|
|||The file open dialog struggles with directories with spaces in them for example, and it treats the filesystem case sensitively on Windows.|
The eggs on the cheeseshop have fared slightly differently. The 2.5 version has been downloaded 871 times to date, and the Python 2.5 ones 98 times.
That makes 1400 downloads in 14 days. Wow.
I suspect most of the cheeseshop downloads come from Turbogears, but even so, that's an incredible response. Thanks to all you users who don't make bug-reports , and special thanks to Nicola Larosa and Robin Dunn for making ConfigObj 4.4.0 possible.
Movable Python 2 Review
It's not been long since Movable Python 2.0.0 Final was released.
Davy Mitchell has posted a review of it :
It's largely positive, although he does have some suggestions for the GUI. I have some more ideas for the GUI, plus some other things I'd like to do with Movable Python. When I'm a little less busy I may start on version three...
PyPy Nearly Useful !
My apologies to the PyPy team for the tongue in cheek title of this blog entry. The PyPy team have just done an exciting new release, version 0.99.0.
I was able to compile a translated binary for Windows using their own 'framework' garbage collection. Attempting to compile with the default garbage collection (Boehm) failed for me.
There are two reasons that PyPy looks exciting to me :
- Creating optimised extensions for CPython with RPython and the extension compiler
- Compiling standalone executables from Python code with the LLVM backend
A compiled executable with the LLVM backend currently runs around 5 or 6 times slower than CPython, so still not very practical. A lot of work has been done on the JIT compiler, but (IIUC) it still isn't plugged in, so expect performance improvements soon.
There is already a toolchain for compiling extensions, although it is marked as beta and in progress. I haven't yet tried it.
There is also a limited definition of RPython in the Coding Guide.
RPython is a subset of Python that can be annotated in order to translate into C .
Restrictions include :
variables should contain values of at most one type as described in Object restrictions at each control flow point, that means for example that joining control paths using the same variable to contain both a string and a int must be avoided. It is allowed to mix None (basically with the role of a null pointer) with many other types: wrapped objects, class instances, lists, dicts, strings, etc. but not with int and floats.
all module globals are considered constants. Their binding must not be changed at run-time. Moreover, global (i.e. prebuilt) lists and dictionaries are supposed to be immutable: modifying e.g. a global list will give inconsistent results. However, global instances don't have this restriction, so if you need mutable global state, store it in the attributes of some prebuilt singleton instance.
all allowed but yield
The extension compiler can compile RPython into an extension that can be used by CPython. Cool.
What would be great is an easy to follow guide to creating and compiling extensions. For example, how do you define the public API of an extension ? I haven't yet tried following the guides in the PyPy documentation, so possibly it isn't too difficult.
If this is already usable then it could be a fantastic tool. For a while it looked like PyPy might be nothing more than an 'academic curiosity' , it's good to see usable results starting to emerge. What is astonishing is that this project somehow got funding from the bloated-bureaucratic-behemoth that is the European Union. How on earth did the EU manage to make a sane and positive contribution to something ?
|||Some of the restrictions are similar to the Python code that ShedSkin (which has also just had a new release) can compile into C++.|
|||And an academic curiosity which killed psyco into the bargain.|
Name of Instances
Here's a simple question for you Python experts . Classes have a 'magic attribute': __name__
Yet if you look on an instance, it doesn't have this attribute. Why don't the normal rules of attribute lookup apply for __name__ ?
>>> t = Test()
Traceback (most recent call last):
AttributeError: 'Test' object has no attribute '__name__'
My guess is that it is because magic attributes are looked up on the class. When you ask the class what its name is, the metaclass answers on its behalf.
The class has no real __name__ attribute, so when you ask the instance (which doesn't inherit from the metaclass) you get an AttributeError. Is this right ? In which case, how does the metaclass (typically type which has many instances) know which answer to supply ?
A simple test indicates that the name is looked up on the metaclass :
... __name__ = 'fish'
>>> class Test(object):
... __metaclass__ = meta
So maybe __name__ is a propery and type keeps a dictionary of instances to names, registered in type.__new__ ?
|||One that has me puzzled...|
On Thursday Andrzej and I leave for PyCon. We will there from Thursday to Thursday, and it will be the first time that either of us have gone to the US.
I'm not sure if we will participate in any of the sprints, as we'd like to explore the area. I have some friends (old next door neighbours) who live 3 hours drive away from Dallas. Apparently this is local ! We will probably visit them, and also possibly look for mountains. North-east into south-eastern Oklahoma is an area containing the Ouachita Mountains. We haven't any fixed schedule for our extra few days, and who knows what will happen...
PyCon itself is looking like it will be really good and I'm very excited. Not only are them some excellent looking talks, but I will get the chance to meet some people that I've only communicated with via the web.
Talks that I'm intending to attend include:
- Developing Desktop Applications with Dabo
- Writing Parsers and Compilers with PLY
- Iterators in Action
- IronPython: Present and futures (plural futures !!?!!?)
- Distributing your project with Python Eggs
- IPython: getting the most out of working interactively in Python
- Securing Python: "Protecting the interpreter from code wielding fresh fruit."
Probably plus most of the testing track on the last day (except the first talk, during which I am scheduled to be unavoidably busy).
The only really painful clash is after lunch on Friday :
- Python-Dev Panel
- WSGI: An Introduction
- Towards and Beyond PyPy 1.0
I'd like to attend all three, but haranguing the Python developers is probably the most fun opportunity !
With a record number of people registered (566 people registered, a 38% increase from last year's number of 410 attendees) it should be a great conference...
YouOS and Python
A natural evolution of 'web as platform' is a web operating system; a computer platform that gives you a desktop in a browser and is accessible anywhere you have an internet connection.
There are a few startups attempting this. One of the better regarded ones is YouOS, which up until yesterday I'd never seen.
Browsing the web from a desktop within a browser is great fun, just uhm... not particularly useful. This is kind of the achilles heel of YouOS (and the whole concept of desktop on the web), what do you do with it ?
However there are more and more applications running on the web. What would be interesting is if google obtained YouOS and integrated their suite of nearly-desktop applications: Writely, Google Spreadsheet, Google Calendar and so on. Integration, so that your documents are saved onto the Youos file-system and then made available locally when you log-on from home, could actually have a purpose. This could even become the not-even-vaporware 'GoogleOS' that has been discussed and debated by everyone except Google.
Of course in computing terms this is a step backwards in the evolution of technology, reducing the client machine to little more than a terminal. The only advantage that internet applications have over client apps is that they are available everywhere you have access to an internet connection. This is the reason I use Google calendar and the reason why many people use Gmail.
Unfortunately, and purely in my opinion, the browser is still a lousy platform to build applications on top of. For example whilst browsing with 'Wherewolf', the context menu of the browser is the context menu for firefox - not for Wherewolf. As far as I could tell there was no simple way for me to open a new page in another tab from within Wherewolf.
Naturally I fired up the 'YouOS' shell and tried running python. Also naturally, it failed to run a python interpreter in the shell.
Creating YouOS applications, that run on the server, would be cool. I emailed the YouOS team and got this response :
Cool. A little googling (it's ok to use it as verb if you actually use google...) reveals the following blog entry :
The entire backend of YouOS is implemented in Python and really is the core of what YouOS is all about.
So far, Python has been a fabulous choice. Coupled with web.py, we’ve been able to build what we think is a powerful and scalable backend. Coming from Java/C++/C background, Python just makes things so easy for me. I love that it has an interpreter. I love the dynamic typing. I love that everything is an object. I love the “help” and “dir” methods. I love the powerful built-in datatypes (tuple, list, dictionary). I love that I can do “*5″ and get a list of 5 elements. I love that my Python code is clean, readable, and maintainable. I love that Python is intuitive and things just work as I would expect. It takes a little while to get used to, but I think once you do, it’s hard to go back to anything else.
This work is licensed under a Creative Commons Attribution-Share Alike 2.0 License.