pythonaro.com

Pythonaro blog

09 March 2010

The joys of Python and Qt

I'm currently working on a tutorial regarding MeeGo, the new Linux-based embedded platform born by the merging of (Nokia-sponsored) Maemo and (Intel-adopted) Moblin. MeeGo is probably the closest thing we'll ever get to a real "Linux for the masses": differently from Android, where Linux is just a kernel for Java to run on top, here we'll have the full GNU toolchain, X display, desktop technologies based on FreeDesktop standards, RPM packages, etc etc.

The main development toolkit for MeeGo, from now on, will officially be QT. This seems to fly in the face of reason, having two existing GTK-based codebases from both "parent" systems which have already been deployed on production devices, but it's actually a very smart choice, as I was reminded just today.

This morning, I was working on a laptop running Windows XP. I built a couple of forms with Qt Designer, then fired up my trusty IDE and wrote the main code, about 150 lines of Python that will download some files, manage a few controls and then display a web page.

After completing a full set of tests on the local machine, I copied it to my (Maemo) phone, and again it was working perfectly -- without any change, recompilation, deployment, anything. Then I went home and copied it back to a different laptop running Kubuntu Linux, and again it was running just fine. Had I had a Mac (or iPad?) laying around, I'm confident it would have run there as well without any change. Consider that the version of QT and PyQt was slightly different on all machines, just to give it a further twist.

Obviously this level of portability has a price. I had to write my code using constructs like QSettings and QNetworkAccessManager rather than messing directly with the Windows Registry or HTTP_PROXY variables. I have yet another (leaky) abstraction layer on top of the OS, which may or may not be to everyone's taste, and the program runs in a sandboxed runtime, which might be slower than natively-compiled code (although this is debatable, these days); but I didn't have to write three different codepaths for each and every interoperation with the OS. I didn't have to worry about having a $HOME or a %HOME%. If I have to worry about packaging is just because I have to write about the ins and outs of a particular platform; in other circumstances I could have simply relied on python tools to do the right thing.

Python and QT could finally deliver the dream of portability that Java promised, if only we give them a sporting chance.

Labels: , , , ,

posted by GiacomoL @ 8:30 PM   0 comments links to this post

07 June 2009

The pains of backward-compatibility

Problem:
  • you have several ZIP and TAR archives
  • you have to replace ONE FILE in each of them
  • you only have Python 2.5

From what I see, the only solution in this situation is to completely branch off the two cases, because the relevant Python modules (tarfile and zipfile) have such a completely different interface.

None of them can simply replace or delete one single file, so you have to unpack the entire archive, edit the file, repack. Inefficient, but consistent approach.
Then ZipFile object will read bytes, whereas TarFile objects will extract files.
Finally, ZipFile doesn't feature a method to extract all files in one go, like TarFile has. To be honest, zipfile sucks in pre-2.6 VMs.
This means that what you can really do (more or less) in the same way (with some essential metaprogramming) is opening/closing archives, listing the contained files, and adding new files.

Things are much, much better in 2.6 and 3.0, where both interfaces are almost the same, but if you are stuck with 2.5 (like me) then you'll have to do with inelegant solutions. And if you are reading this, maybe you'll waste less time.

(Memo to self: always, ALWAYS do the easiest thing that could possibly work, no matter how inelegant it is. Premature optimization really is the root of all evil.)

Labels: , , ,

posted by GiacomoL @ 7:54 PM   2 comments links to this post

01 June 2009

note to self

When you start writing hacks like this:

for attr in ['Something1','someThing2'...'SomeThing215']:
    self.__dict__[attr.lower()+'Widget'].do_something(someValue)
    self.__dict__[attr.lower()+'Widget'].set_parameter(someparameter)
... it's probably time for a subclass.

Labels: ,

posted by GiacomoL @ 9:08 AM   2 comments links to this post

30 April 2009

zipfile quirk

In Python 2.6.0, a bug in the zipfile module makes the newly-acquired extractall() method basically useless. The function is supposed to extract all members of a zipfile, "no questions asked", like Windows would do with a right-click "Extract All..."; unfortunately, the original implementation makes it fail when the zipfile contains subdirectories. The behaviour was corrected in one of the 2.6.x maintenance releases (and 3.0.x, and 2.7), but if you have the misfortune to be stuck with 2.6.0, here's the banal workaround:
zf = zipfile.ZipFile(zpath)
zlist = zf.namelist()
for filename in zlist:
 if filename.endswith("/"):
  destpath = os.path.join(path_to_extract,filename[:-1])
  if not os.path.exists(destpath): os.makedirs(destpath)
 else:
  zf.extract(filename,path_to_extract)

Labels: , ,

posted by GiacomoL @ 9:22 AM   0 comments links to this post

01 April 2009

Eric4 startup crash on Windows

This post is for google.

If your Eric4 for Windows keeps crashing on startup, try the following:

  1. Start eric4-tray.py (which should be in your PYTHON_HOME\Lib\site-packages\eric4)
  2. Right-click on the Eric icon tray, and select Preferences
  3. Change something in the Application section, and click Apply then Ok
  4. Right-click again on the icon, and select "Eric IDE". This time it should start ok.
  5. Now you should be able to quit the tray application and start Eric as usual

Labels: , , ,

posted by GiacomoL @ 9:10 AM   2 comments links to this post

04 March 2009

On The Burden Of Legacy

I recently thought it would be good to write a few utilities for one of the products I support. This product was built on DCOM (don't ask me why). Obviously, being a pythonaro, I just had to use Python. And so my tribulations began.

Python supports COM objects thanks to the lovely Win32 package by Mark Hammond. When you have a DLL that you want to use in python, run "makepy.py yourlib.dll" (or just makepy.py, and browse through the registered libraries to choose one) and lo, it's available as a first-class python module. So I do that, and start poking around with various stuff, and eventually I call a method that returns an object whose definition is in another DLL, so it only comes up as a PyIUnknown object. Ah well. I run makepy.py on the second DLL, to no avail.

After a bit of googling and fiddling, I finally stumbled on the right incantation.

myobj = win32com.client.Dispatch(myobj.QueryInterface(pythoncom.IID_IDispatch))
myobj = win32com.client.CastTo(myobj,'MyIClassName')
Basically, I have to find the right interface ID for the object, dispatch it, and then recast the object with a different type which is specified by a string. Man, isn't that ugly. Not because of having to recast (which I can understand) but because the recasting needs the class name as a string, you can't somehow derive it from the object. If you don't know the "secret" class name, you can't use its methods even if you know it's of the right type. From a modern OOP point of view, this is quite absurd... but there is an explanation.

COM was built when reflection was not yet mainstream, and types were static and immutable. Programmers were used to declare types for each variable, and if the type wasn't right, the compiler would cry. Polimorphism, reflection and dynamic interpreters were slowly reaching mainstream acceptance, but Microsoft had to retrofit them on top of existing frameworks, one feature at a time. The result was the incomplete hybrid I now have to deal with.

Well, I thought, this open-source CPython stuff in Redmond is considered akin to communism, no wonder it doesn't play well with old MS frameworks. Let's try to move further down "the Microsoft Way" and see if things improve: I shall use IronPython. After all, it's just a thin layer on top of the .Net CLR, right? Certainly it will be able to guess types a bit better...

So, a few installs later (you need at minimum the "Windows SDK 6.0" for good interop tools for .Net 2.0, plus the IronPython installer), there I was, trying to do the same thing.
The .Net version of makepy.py is called "tlbimp.exe", and it will basically build a new DLL to wrap the old one. You then import the new DLL in IronPython and lo, you can use the objects. But what happens when a function returns a reference to an object not defined in the DLL? Well, more or less the same thing as for win32com -- you get an unknown interface. So again,you have to wrap all the other DLLs, and explicitly instance these objects with the right type. Slightly better but not really that much different (so I'll stick to CPython, thank you).

As I said, this sort of explicit casting was perfectly acceptable 15 or even 10 years ago. But honestly, don't we live so much better without ? Why win32com and (more damning) IronPython cannot yet look up this sort of thing automatically? I understand that I'm working with legacy interop, but still... this sort of "programmer usability improvement" would help a lot in real-world situation where The Big Rewrite is simply not an option.

Labels: , , , , ,

posted by GiacomoL @ 4:10 PM   1 comments links to this post

16 January 2009

jEdit macro to add encoding declaration to python files

This is a little macro to add a PEP263-compliant string at the top of all open buffers in jEdit. It should probably be improved to skip the shell declaration line (if there), and not operate if the line is already there -- feel free to send patches ;D

Download Add_Encoding_Decl_to_Buffers.bsh

Labels: , ,

posted by GiacomoL @ 11:51 AM   1 comments links to this post

29 December 2008

Guido van Rossum on speed and the array module

Giulio (through his feed on Delicious.com) pointed me to a nice post from "benevolent Python-dictator" Guido van Rossum. The essay describes a few general rules for improving performance of Python programs, and it also reminds us of "an odd corner of Python", the array module. Go and read it, it's worth it.

It also made me discover "an odd corner" of the Python website: the collection of Guido's essays. As demonstrated by the original post, this page is much more interesting than Guido's own blog, and so it's very disappointing that it doesn't have a feed to monitor. Mmhh... Edit: well, stuff there looks a bit stale, I guess Guido doesn't use it very much anymore. Still, it's the sort of thing that should have a feed. Maybe python.org should move to django? ;)

Labels: ,

posted by GiacomoL @ 2:36 PM   4 comments links to this post

06 December 2008

If only we could re-use stop-energy...

I confess: I'm a whiner, a moaner, a reactionary bitch. I like to pundit and joke about new things, it's actually much easier than making new things, isn't it... You can just wait there and shoot from the hip, it'll make you feel all righteous and smart, and it's free!

Italians are champions at moaning.
Fat lot of good it does to our GDP.

You probably already know that Python 3.0 was released a couple of days ago. After the first 24 hours of joy, the inevitable wave of stop-energy hit the crap-blogo-sphere, mostly in the form of classic concern-trolling or uninformed criticism. Now, this is inevitable; for every big action (and releasing Py3k was a huge step) produces a reaction.

The transition to Python 3 was announced eight years ago, discussed in detail for ages and eventually implemented in the last two years. Dedicated tools helping the porting effort have been developed and work pretty well, certainly better than most VB6-to-.NET wizards released by Microsoft around 2001. The old codeline will be maintained and updated for well over a year from now, with at least another major release planned, so there's no hurry to upgrade, no pressure whatsoever. Documentation of the changes is pretty exhaustive. Major third-party apps and libs have been ported already or are in the process of being ported.

So, what's left to moan about? Breaking backward compatibility. The very first thing that was announced 8 years ago, and since discussed in the most excruciating details, to the point where the "major changes" seem almost banal.

"Yeah, we got great Unicode support and the with statement, but so what? print is now a function! That's it, I'm switching to Ruby!"
"Wait, did you ever actually use Python? Do you know how much painful it was to work with Unicode? Or all that crap about new-style and old-style classes?"
"Well, I don't really know the language much..."

Stop-energy is for losers and trolls. Ignore the bitching, Python 3 will rock.

(now, if only I can manage to compile the flipping thing...)

Labels: , ,

posted by GiacomoL @ 1:09 AM   3 comments links to this post

20 November 2008

Python "global" weirdness

I'm sure there's a rational explanation for this behaviour, but at the moment is slightly baffling.

class SomeObj:
 def __init__(self):
  self.prop = 1

class SomeClass:
 global objInst
 def __init__(self):
  self.reference = objInst
  self.reference.prop += 1
  
if __name__ == '__main__':
 global objInst
 objInst = SomeObj()
 clsInst = SomeClass()
 print "original:" + str(objInst.prop)
 print "clsInst:" + str(clsInst.reference.prop)

# output:
# >>> x:2
# >>> y:2

This is all good, and expected: you get a reference to a global object and manipulate it. But what happens if you try to rebind that global name straight in the __init__ method?

[..]
class SomeClass:
 global objInst 
 def __init__(self):  
  self.reference = objInst
  self.reference.prop += 1
  objInst = SomeObj()
[..]  
# output:
Traceback (most recent call last):
  File "test.py", line 16, in 
    clsInst = SomeClass()
  File "test.py", line 9, in __init__
    self.reference = objInst
UnboundLocalError: local variable 'objInst' referenced before assignment

And it gets even more weird! If you move the "global objInst" declaration inside the __init__ method, it works as expected: objInst is bound to a new object with a different state from the one in self.reference. But if you keep the declaration at class level, and simply move the rebinding out in a new method (separated from __init__), you don't get an error but python does not bind the global to a new object.

I guess it's somehow all a matter of context, and it probably makes perfect sense to programming-language scientists; it just doesn't to me :)

Labels: ,

posted by GiacomoL @ 1:26 PM   2 comments links to this post

05 October 2008

Horrible Hack to get Python 2.6 on Debian or Kubuntu

I wanted to try out the newly-released 2.6 version of our beloved Python, but unfortunately Debian didn't have a package for it yet (and it still doesn't). I wasn't too afraid of screwing up my laptop, as it's probably going to be formatted very soon anyway, and I didn't want to mess around with deb build scripts, so this is what I've done:

  1. got the official source distribution, untarred and cd in the resulting dir Python2.6
  2. got some additional packages: apt-get install tk8.4-dev libgdbm-dev libdb-dev libreadline-dev libsqlite3-dev libncurses5-dev (and possibly a few others)
  3. ./configure --prefix=/usr --enable-ipv6
  4. make
  5. checkinstall -D --pkgname=python2.6 --pkgversion=2.6 --maintainer=g.lacava@gmail.com --inspect --backup=yes --install=no make altinstall
    This command allowed me to review the package contents and remove what I didn't need, which is basically everything outside the "python2.6" directories and which might already exist on my system (so I didn't want to overwrite it).
    I took out the lines /usr/bin/pydoc, /usr/bin/idle and /usr/share/man/man1/python.1
    UPDATE: when checkinstall asks if you want to create a default set of docs, say "yes", or you might get an error about ranlib further down (see comments).
  6. installed the produced .deb package
  7. copied back pydoc and idle (from the build directory) and /usr/share/man/man1/python.1 (from the Misc directory), all with "2.6" appended. I then set up alternatives with update-alternatives --install symlink name alternative priority (mainly in order to "redebianize" my impure karma); UPDATE: well, using alternatives (a 100% Debian solution which works perfectly well for loads of other multi-version script engines) will break your system, because some developers absolutely must reinvent the wheel every 5 minutes and then proudly announce that bugs won't be fixed. The stupidity of it all is staggering.

First impressions: 2.6 seems fast as hell. I don't know if this is due to the custom compilation though, rather than improvements in the runtime.

Labels: , , ,

posted by GiacomoL @ 2:14 PM   13 comments links to this post

16 September 2008

on PyconUK 2008

Great conference, like last year. Interesting talks, nice people, spotless organization. Go to the PyconUK wiki if you want slides and (in a few days) recorded audio.

Next year the same bunch of great guys will host EuroPython, in June. I'm sure it will be fantastic, but I don't know whether I'll be able to attend, as it will happen during weekdays and I probably couldn't justify the absence from work. Apparently it's all because the French don't go to conferences during weekends; it's always their fault, isn't it ;)

Anyway, it was all good energy to start messing again with Django on a magnatune-inspired project. Also, we'll try to "reboot" Python North-West and see if we can stabilise it a bit. It's all fun :)

Labels: , , ,

posted by GiacomoL @ 12:13 PM   0 comments links to this post

11 September 2008

Off to PyconUK

So, tomorrow night I'm off to Birmingham to attend Pycon UK. I don't think I'll liveblog like last year, I'll try to be more social. To be honest, I'm not as excited as last year, probably because the conference was so good in 2007 that I doubt they'll be able to top it. This said, let's hope I'm wrong (as usual).

Labels: , ,

posted by GiacomoL @ 9:17 PM   0 comments links to this post

15 August 2008

django on jython

You can now run Django on Jython, as announced by Leonardo Muñoz. Lovely. I really should go back hacking django a bit.

Labels: , , , ,

posted by GiacomoL @ 4:27 PM   0 comments links to this post

05 June 2008

Early pythons get the bird -- book PyConUK now!

I just reserved my place at PyCon UK 2008, which will again be held at the Birmingham Conservatoire on the second weekend of September (12/13/14). If you like Python and you can make it, you should: the vibe last year was great, the talks interesting, and the organisers a nice bunch of geeks. The extra-early-bird offer expires on June 9, so be quick and you could save a few pounds!
If you come, take a minute to RSVP on the official PyConUK 2008 Facebook event page; the more people there, the better visibility (and credibility) we get. Also, if you are on other social networks, you can do something similar to aggregate interested people.

Unfortunately I can't make the Friday tutorials (I'm saving days for a big trip to Japan in October), but I'm sure Saturday and Sunday won't be disappointing. See you there!

Labels: , , , ,

posted by GiacomoL @ 8:43 PM   0 comments links to this post

16 May 2008

for everything else...

  • Do you need to convert WMA files to MP3?
    Just use the free PyMedia library.
  • Do you need to upload these files to an FTP?
    The ftplib module is included in the standard Python library.
  • Do you need to schedule this upload?
    The standard Python library gives you the sched module.
  • Do you need to persuade some people to pay you a (minimal) amount of money for the (minimal) effort of writing the script?
    I'm afraid you'll have to do that yourself...

There are things a computer cannot do.
For everything else, there's Python

Labels: , , , , ,

posted by GiacomoL @ 11:18 AM   2 comments links to this post

08 April 2008

Google App Engine

Google App Engine. Write applications in Python using a WSGI-compatible application framework, then host them on Google’s highly scalable infrastructure.
(via Simon Willison's Links)

"Holy s**t" was Ryan Tomayko's comment, and my first thought as well. Google is realising the promises of WSGI, and what a sight it is.
On one hand, this is fantastic; it made me think of "J2EE done right". On the other hand, if you use GAE, you are handing your entire infrastructure and data (!) over to Google, which might not be the smartest move for lots of companies (any FTSE100 for example, and probably any NASDAQ-listed as well).

Anyway, Python rocks.

Labels: , , , , ,

posted by GiacomoL @ 12:04 PM   0 comments links to this post

22 February 2008

kdepyuic essential patch

This little patch for kdepyuic just made my day.

kdepyuic is a small utility to produce python files from .ui files produced by QtDesigner, ready to be used in PyKDE applications; it basically adds KDE-specific stuff to the standard pyuic utility (a .ui-to-.py compiler included in the generic PyQt distribution).
This i18n patch (courtesy of Stephan Hermann) solves a few headaches with importing the correct i18n function to translate stuff, and I'd strongly recommend everyone writing KDE apps in python to apply it.

(... and this means that a kdelicious release is on its way...)

Labels: , , , , , ,

posted by GiacomoL @ 7:39 AM   0 comments links to this post

18 December 2007

KDelicious 3.0 (+ roadmap)

After a few days of obsessive bugfixing, I've finally released KDelicious 3.0.

This is a big step forward from pykeylicious: it now uses PyKDE components to save preferences and interact with the network, which means transparent support for proxies and KWallet.

On the usability side, I've moved the option "Tag this post on del.icio.us" to its natural place, out of the submenu. There's now a GUI to manage options, which means that you can now switch del.icio.us username or choose how to rearrange your locally-synchronized bookmarks, all from a nice and simple interface.

Unfortunately, the resulting proliferation of files forced me to adopt a "proper" installer mechanism, and for now I settled on distutils. This has one major drawback: non-root installs are much harder than they used to be, if you don't know your way around python.

Mainly for this reason, I (foolishly) decided to maintain two codelines. Pykeylicious 2.x will still be available for people who can't be root or don't have/want the KDE bindings for python, in bugfixing mode. It will not have support for proxies, unless somebody else hacks it in. I hope this doesn't come back to bite me; I'm actually tempted to "downgrade" pykeylicious to 1.0, which got better feedback than 2.0.

In the short time (3.1) I'd like to get rid of all calls to kdialog. I resisted up to now because they work and are fairly low-maintenance, whereas using the proper bindings need a little bit more infrastructure, but they are really ugly and slow and I hate when dialogs stick around after the program crashes. I am also tempted to use the python-dcop bindings, but they look complicated and dcop is going away in KDE4 anyway, so I don't know if it's worth it.

One thing that didn't make it in KDelicious 3.0 is support for Ma.gnolia.
I personally don't use the service, but they (very cunningly) expose a mirror of the del.icio.us API to allow for an easy switch, so adding the new backend shouldn't be too time-consuming. Unfortunately they don't support bundles, which in KDelicious are very useful for sorting the locally-synchronized bookmarks. I'm thinking to add this "multi-backend" option in 3.5.

For 3.2 I might package it for debian. The only reason for the effort is to have an "uninstall" option, that distutil hasn't. It's a boring job, but probably necessary. I'll also try out other del.icio.us plugins to steal featu--- ahem, get "inspiration" for new features.

By the time all this is done, KDE4 will have been around for a while (see my previous post)... KDelicious 4 might be a very nice app by that time ;)

Labels: , , , , , ,

posted by GiacomoL @ 1:19 PM   0 comments links to this post

17 December 2007

Things I learnt last week on Python, PyKDE and KDE

  • if PyKDE segfaults on you, don't despair: you are probably just using the wrong arguments for a method call. Get the right invocation and you'll be fine, no need for recompilation or other drastic measures.
  • KCmdLineArgs is cool!
  • how to use KConfig from python (saves so much time):
    conf = KConfig("your_rc_file") # ends up in $KDEHOME/share/config/
    conf.setGroup("yourgroup")
    conf.writeEntry("your_option","your_string")
    # non-string values DON'T work
    conf.sync() # this will actually write out the stuff
  • KIO.NetAccess can save a lot of trouble storing passwords etc., seamlessly integrating with konqueror and kwallet
  • distutils is cool, in its own way. PyPi integration looks terrific, can't wait to upload my stuff there...
  • dependency checking in distutils still sucks. Either you go with setuptools, or you have to litter your setup.py with ugly import tests.
  • kdedistutils (from pykdeextensions) looks useful enough
  • the KDE TechBase is very good for KDE4. For KDE3, better to get the kdelibs-apidoc packages in your distro. Don't understand why (on Debian Etch) it doesn't register with QtAssistant.
  • Google Translations can be weird.

I'm very close to releasing "KDelicious 3.0", which is a big improvement on pykeylicious. While adding a few "simple" options to manage how del.icio.us bookmarks are imported into Konqueror, I tried to refactor out nontrivial code from the main script into modules, and added a GUI to manage these options. I also pushed the integration with KDE in order to do things like transparent proxy support and kwallet integration, which spared me from maintain connection code, passwords, etc... I ended up with several files to distribute, which required a "proper" installer.

This release will still use the kdialog hacks. I'll get rid of them in 3.1, because I really want to put this out before the end of the week and get some feedback.

On bookmark synchronization: in an ideal world, synchronization would be done in the background, if we are online, every couple of hours, and by just pulling the more recent posts. But this is a bad world, and I'm a bad coder... KDelicious will only synchronize manually, will download all your bookmarks each time it runs, and will just try to stop you from getting banned by del.icio.us if you launch it too often. The only way around this would be to write a KService or a systray applet (which would also allow me to support other "minor" browsers like Opera), but this stuff is changing in KDE4 so I don't want to spend time on it before march.

After Christmas I'll think about putting the code on sourceforge (or savannah, or something) and have a proper homepage for it. But first, let's release ;)

Labels: , , , , , , , , ,

posted by GiacomoL @ 2:46 PM   0 comments links to this post

04 December 2007

pykeylicious 2.0

Why stop when you're having fun? :)

pykeylicious 2.0 is out, with a brand new feature: local synchronisation of your del.icio.us bookmarks! I hope people will like that one (and the few bug fixes here and there).

Now I'll probably take a break; further features (heck, even the current ones) will require a configuration screen, and there is only so much you can do by leveraging kdialog. The logical step would be to implement a "proper" PyQt application, which will require a bit of time and effort; in the short term, I'll probably just release a 2.5 version to support system-wide installs (the only feature from konqil.icio.us that I didn't replicate).

Labels: , , , , ,

posted by GiacomoL @ 10:35 PM   0 comments links to this post

29 November 2007

On pykeylicious, Python vs Perl, and the state of Konqueror

If you use KDE, as I do, you should check out KDE-apps; it's a nice site full of all sorts of programs and add-ons for the desktop environment, from full-featured applications like K3B and Amarok to simple enhancement to the UI, kicker replacements, etc etc.

On this site, there is a fantastic little feature that allows you to "subscribe" to an application; when the application is changed/updated, you get a reminder via email. I personally subscribed to a few little apps (KShutdown, QtEmu, kio-locate...) that are not included in the standard KDE and are often off-the-radar for mainstream distribution packagers, so they are a bit difficult to track in the regular ways.

One of these apps was konqil.icio.us, an addition to the Konqueror right-click menu to do a few things with del.icio.us. Last night I found the email saying that a new version was out, so I went there and downloaded it; while reading the description, I immediately thought "why do I need to do all this messing with folders and permissions, a little installer could do it for me!". Then I checked the dependencies, and found that the script was in Perl... there was no chance I'd write an installer in Perl (I hate it) and send it to the original developer; also, adding a dependency on python for the installer looked a bit silly. So I decided to rewrite the script in python, add the installer, and upload it, and pykeylicious was born.

All this reminded me of how easily "tweakable" Konqueror (and KDE in general) is. You add a file in the right place under $HOME/.kde/, and you have just hooked the interface to your programs and scripts. The problem is often finding the right place; documentation exists in non-obvious places, as KDE developers tend to talk more about the C++ infrastructure.

I personally think this is one of the factors that stopped people from moving to Konqueror from Mozilla/Firefox: developing third-party extensions seems hard in comparison. This might or might not be the case; as konqil.icio.us demonstrated, it is fairly trivial to build a simple extension... however, if you want to manipulate webpages and the internal DOM, you have to write a C++ plugin, which might be easy for C++ coders, which net-people usually are not. Net-people like "easy" languages like java, javascript, python or ruby.

Last time I brought this up (yes, it's one of my pet-subjects) on the pykde list, I found out that yes, you can probably build plugins in python, but you have to jump through several hoops and basically try to fake that you are a C++ program. Not good enough. The day this sort of things becomes easy is the day that Konqueror goes back to be a serious alternative to FF in the Linux world.

Labels: , , ,

posted by GiacomoL @ 5:19 PM   2 comments links to this post

21 November 2007

On the Samurai Principle

Some blogs recently pondered on the Samurai Principle. It made me think, because I'm one of the many "guilty" of returning None/null rather than raising an exception. To me, it happens more often when working with Python rather than Java, because it's very natural to write "if something_not_found: return None". Also, abusing exceptions can end up polluting your code with dozens of nested try-catch/except, which kill readability and tend to be much worse than a simple "if (obj is None):".

This said, I agree that NullPointerExceptions are a royal pain, and "AttributeError: 'NoneType' object has no attribute 'something' " is equally bad to deal with. API programmers in particular should try hard to return this sort of stuff as little as possible.

I guess the bottom line is that in medium stat virtus, as it's often the case with these "absolute principles of programming"; at the end of the day, when we program we are applying science, not demonstrating it. And as much as we love them, samurai lost all their wars ;)

Labels: , ,

posted by GiacomoL @ 1:40 PM   3 comments links to this post

10 November 2007

Notes on Python-North-West 2nd meeting

I just posted some notes on the second Python North_West meeting in "Happenings in Python User Groups". And also some notes on the new IRC channel vs the Facebook group.

Labels: , , , , ,

posted by GiacomoL @ 7:07 PM   2 comments links to this post

29 October 2007

Pain can be useful

So, I've spent a few hours improving my little J2ME project. It's pretty much done, what I need now is a little bit of polishing and, more importantly, the server-side app, which I just started to "conjure up" in django.

I didn't remember how painful Java development can be. Fixed-size arrays, .put() and .get() every five seconds, loads of redundant declarations (if a method can only return a String, why should I also declare that a reference to the result is of type String? what else could it be?), not having an interactive environment to quickly test out ideas. Eclipse goes a long way to reduce the pain, but it's still so much more painful than doing the same thing in Python. And when everything is done... NullPointerException.

The good side is that fear of pain forces you to really think things through before you write them down. In Python, I end up re-writing things over and over again, because there's no (perceived) penalty in doing it, and I more or less "code my thoughts"; of course, I eventually end up spending lots of time on this sort of messing.
With Java, I'm forced to think about the proper structure up-front, because I dread having to write it down more than once; but this means that it's then a matter of monkey-coding a clear structure, and once it's done, it's done, and I can get on with other things.

Labels: , , , ,

posted by GiacomoL @ 2:51 PM   4 comments links to this post

Python North-West meeting

Tuesday, November 6, 2007 - 6:30 PM at MDDA (Lower Ground Floor, 117-119 Portland Street, Manchester, England M1 6ED)

New meeting of the Python North-West community!
Michael Sparks will talk on "Greylisting using Kamaelia", how to reduce spam using the Kamaelia framework. See this post from Michael's blog for some details.

After the talks, people will be able to showcase their cool python stuff, get tips from others, or just have a chat with fellow-minded python geeks.
Free wifi and refreshments will be provided! Feel free to bring your gear to showcase cool python hacks.
If you want to give a talk at this meeting (or the next one...), just post the idea on the mailing list or drop me a message.

Labels: , , ,

posted by GiacomoL @ 1:34 PM   0 comments links to this post

Empowering programs

I remember being impressed, more than three years ago, by this post by Joel Spolsky on Microsoft's "Empowering" partner program. It looked like Microsoft was (for once) doing the right thing to help the little guy.

Now that I'm starting to explore the possibilities of setting up shop by myself, I'm looking around for similar programs; I don't plan to use MS stuff, so Empower is simply not for me. I intend to use mainly free open source tools at the moment, but chances are that sooner or later I'll have to pay my tribute to some Big Company, so it might be good to get some info on ways to save a few bucks or get good tech tips.

My biz plan involves J2ME apps, Python (for django, so web stuff) and the inevitable database; it might (or might not) include some very small (and collateral) piece of desktop software sometime in the future.  A proper custom-built server will probably enter the equation very soon, and sooner or later I'll need new hardware anyway. So, what's out there that might interest me?

First I checked the Sun Partner Advantage program. It seems to consist mainly in hardware discounts (fair enough, they are first of all a hardware company... aren't they?); the Mobile initiative is limited to big players, not everyday members (bad, bad move). Not sure is worth the hassle, as their gear is really uber-priced and I couldn't ever make them my preferred hardware supplier. I might be wrong though; the Sun website is a perfect reflection of the company: huge, disparate, often byzantine, full of hidden gems here and there as well as boatloads of useless marketing spiels... I might have missed the great bits, who knows.

I've also looked into the Trolltech partner program, for the (inevitable) little desktop bits. As much as I love the technology, anything technically significant comes with the $1500/yr option; overall, it feels more like a commercial relationship than technical partnership. Probably too pricey for what I need.

Uhm, what else? Where's the killer partner for new mobile/web startups?

Labels: , , , , ,

posted by GiacomoL @ 1:30 PM   0 comments links to this post

03 October 2007

Post-meeting

I published my django presentation slides on the Files section of the list page (in ODP and PDF).

My notes on the meeting are in the relevant post at Happenings in Python Usergroups.

I certainly enjoyed it, and I hope the other guys did too. The presentation was ok (even though I slightly fudged the demo, and didn't really go too deep into details); I think people enjoyed the overview, and I tried to communicate what django was all about, more than showing clever tricks or how to satisfy obscure requirements.

Who knows, maybe one day I'll actually make a living out of this stuff...

Labels: , , ,

posted by GiacomoL @ 12:25 PM   5 comments links to this post

26 September 2007

Python North-West meeting

So here it comes!
We sorted out the location thanks to the fantastic Manchester Digital Development Agency. They offered us their room free of charge, with projector & free wifi! For once, I'm very happy about paying taxes (MDDA is funded with public money).

The first meeting of the Python North-West community will feature a short talk on Django, "the web framework for perfectionists with deadlines"; I'll share my experience in building a django-powered site using some of the "contrib middleware", and what you can expect from it. I'm confident I'll lower the bar so much, that people will step up for further talks real quick ;)

Then people will be able to showcase their cool python stuff, get tips from others, and just have a chat with fellow-minded python geeks. Since there's free wifi and the room is secure, laptops are welcome!

If anyone wants to give a talk at this meeting (or the next one, or the one after that...), they can post the idea on the mailing list or contact me. Michael Sparks will probably talk about "Greylisting with Kamaelia" next month.

I also created a Python North-West Google Calendar, to track meetings & other stuff: feed - iCal - HTML.

See you there!

Labels: , ,

posted by GiacomoL @ 7:51 AM   2 comments links to this post

10 September 2007

Introducing Python-North-West

On the wave of the great time we had at Pycon, it was decided we should have a proper mailing list dedicated to North-West-based Python users... so here it comes!

The list is open to everyone in the area who loves coding/playing/enjoying Python. To join, you don't need to know your django from your pylons or your pyqt from your wxwindows... and certainly you don't need to pronounce WSGI. Don't worry, it's going to be uber-informal and very low-traffic, and I promise we won't use lolcats (not much anyway).

You can subscribe from the Python North West googlegroup page. Introduce yourself to fellow pythoneers, talk about your Python projects... you might get help!

Ideas on how to link this to other social software (facebook etc) are welcome.

Labels: , , , ,

posted by GiacomoL @ 8:19 PM   0 comments links to this post

PyCon UK fantasy stats

 Thomas Guest (aka "the one with the freaky 70s shirt", aka "pitch Python as "high-level" language") invented statistics which look pretty accurate:

I’ve invented some statistics about the conference.

  1. 123% better attended than first predicted
  2. 72% of laptops used were apple macs
  3. 50% of keynote speakers were female
  4. 20% of conference organisers were female
  5. Less than 1% of the remaining delegates were female
  6. Sessions were 99% punctual
  7. Virgin trains to and from Bristol were 68% punctual
  8. Beautiful Code, a book I’d hoped to browse at the book-stand before buying, was 100% sold out just 10% into the conference

PyCon UK: statistics, pictures and perennial problems

I think the only one he got wrong is the first 123% (my guess is 160%+), but only Midlands guys can tell. And hey, 3 statistics about female attendance... Thomas, did you hope to pull?

I'll add my own fantasy number too:

  1. 70% couldn't pronounce WSGI (whiz-gee? whis-ge-hai? double-u-es-WTF ?).
  2. 20% of attendees were Django junkie, 20% were Turbogears supporters, 20% said a prayer to Pylons before every meal, and 40% didn't really care as long as it got the job done.
  3. 100% of available large-sized Debian t-shirts were bought in the first 10 minutes.
  4. 90% of lightning talks were cut short (people talk too much! off with their time!).
  5. 10% of lightening talks were kind-of-related-to-Python-but-not-really (I'm not complaining here, just had a couple of WTF moments).
  6. 100% of the attendants to the PyQt tutorial loved the Trolltech goodies.
  7. 100% of dinner attendants thought Jono Bacon was funny, or they were already too drunk to notice.
  8. 20% of all clapping time was reserved to John Pinner. We should raise it to 30% by law.
  9. I didn't know 85% of North-West pythonistas who showed up.
  10. 3% of attendees got a prize. One of them even renounced his prize out of sheer generosity.
  11. 15% were over-50, which means it's never too late to learn Python.
  12. 15% were under-21, which means it's never too early to learn Python.
  13. 5% were labeled "Large Type" on their badge. I suppose it's better than "Medium Unbounded Variable" or "Extra-Large Exception".
  14. 5% of presenter used lolcats in their slides.
  15. 30% were a bit uneasy eating food bought by Microsoft, and made sure it wasn't poisoned before trying it. (MS geeks were awesome anyway.)

Labels: , ,

posted by GiacomoL @ 11:56 AM   0 comments links to this post

09 September 2007

See you next year!

PyConUK is now done! Thanks to all the amazing people at Python West Midlands and Python London! Also to all the sponsors (Revolver, Microsoft, Trolltech, and all the others -- including Ravenbrook!)

The breaking news are that not only PyconUK will happen next year too, but John Pinner wants to submit a bid for EuroPython 2008/2009! woot woot! John, you are full of win.

Oh, sorry if I didn't liveblog the last few talks, they'll be posted to the pyconuk site anyway. The presenter for the (impressive) gSculpt project won the xBox (bad! it lowers productivity!) and Mr. Etienne from Belgium was the lucky N800 winner! (and btw his ideas are very worth checking out, if you are a medium-small python shop interested in public money you should check it out and consider proposing to the EU commission or something).

Labels: , , , , , , ,

posted by GiacomoL @ 6:32 PM   0 comments links to this post

Liveblogging PyconUK 2007 - Sunday

Whew, was saturday a busy day! Simon Willison's keynote on OpenID was disappointing, he basically responded to any critique of the (flawed, IMHO) security model by saying "well, recovering passwords through email is as insecure as this!" which is balderdash :) (there are legal QOS agreements between email providers) and then "well, of course banks will never use this, but your generic stuff might" which again is balderdash because even people behind "generic" stuff do care about security of their data UPDATE: see Simon comment further down for clarifications... Simon is a good speaker, but feedback from people was still sceptical to say the least.

Dinner was awesome, met lots of great people and Jono "LUGRadio" Bacon delivered a "rock&roll" after-dinner (what next, LUG-StandUpNight?) on why his pet-project JoKosher ended up being written in Python, and be fairly usable in less than a year (for an audio editor, apparently, that's a good timescale).

And we start again! David Boddie on the awesome QtDesigner, looks easy to do custom widgets, and autoconnecting features promise to do away with the signal/slot paradigm as much as possible.

UPDATE: Jonathan Hartley on the basics of TDD in python; I was probably expecting a more "theoretical" talk, or something more advanced, but it was just an introduction really. I suppose I should just be glad I already know about this, stop being lazy and JUST. TEST. IT.

UPDATE: The European Union gives 2.5 million euros to the SQO-OSS people to find new ways of measuring software quality: impressive! Paul Adams made an important point on developer turnover and how to get people on your project: open it! (mailing lists, wikis, svn, etc).

UPDATE: the presentation on Python EGGs was very informational, there are lots of ways on which you can use easy_install, not just to install stuff but also to update it, have multiple versions, get svn versions of installed software, and aslo package un-EGGed software. It's a shame that the presenter was trolled in Q&A time, it shouldn't have happened.

I confess I didn't really listen to the Pylons/WSGI talk. Middleware doesn't really turn me on. I filled in my (great) feedback form for a chance to get my dirty hands on a Nokia N800 -- apparently the best presenter will get an Xbox! Lunch was also sponsored from Microsoft, am I supposed to feel guilty? ;) I see the first slides are being posted online already, I shared some of them in my Google-powered sidebar feed as I find them, I'll try to link them all in the next few weeks, many were also recorded so they should appar on the pyconuk site.

I'm almost sad that in only a few hours everything will be gone... My target now is to have a lighting talk next year on my (very cool) django-powered app! The countdown begins, better start coding...

Labels: , , , , ,

posted by GiacomoL @ 9:21 AM   5 comments links to this post

08 September 2007

Liveblogging Pycon UK 2007 - first notes

Lots of people, fantastic atmosphere, lots of kudos to the Birmingham user group. "Msdn magazine" in the goodie bag sounds like MS really wants to invest in Python, that's probably why Sun decided to go on Ruby instead.

First talk on SQLALchemy by Paul Johnston, very very interesting, too bad it was a bit squeezed, another 15 minutes would have helped. Must investigate the reflection vs autoupdate stuff & migrate (django doesn't manage db changes very well at the moment).

Second talk: Mr. Voidspace (Michael Foorde) on Silverlight & IronPython -- lots of possibilities there, but still very very early. 1Mb of local space is very little for serious usage, there are accessibility issues (but possibly less than Flash) and limitations (1 Canvas only). But having an embedded mini-CLR/DLR in every browser (currently IE/FF/Safari, with Opera in the works) gives me a feeling of "ActiveX done right", something Java should have done 5 years ago.

Made contact with other Manchester pythonistas, it's really true that pythons hide under rocks! Looking forward to build a community in Manc when we go back, people really wants to invest serious time on Python apparently. Oh, and Resolver is hiring, but it's London-based and they do Xtreme (pair) programming, so no telecommuting, but if you are in the area and you fancy "coding the way Guido indented it" give it a go, they seem very nice guys.

Time for Django stuff with Simon Willison!

UPDATE: Simon rocks. Fast as lightning and to the point, lots of goodies for serious django usage, I hope the session was filmed because it was really worth it.

UPDATE: I met Phil Thompson, the creator of PyQt! Jeez, I probably sounded like a fanboy (that I am). And I also met a guy not just from around Manchester -- from Stockport! Astonishing, the world is so small these days. Am now on the PyQt tutorial from Mark Summerfield (who has a book finally coming out on PyQt! fantastic), Trolltech provided some very nice freebies. I feel in geek heaven.

UPDATE: Mark was great, but 2 hours straight are a bit much, so in the end the class was clearly a bit tired. Will definitely go back to his presentation very soon. Break now, then on to the lightning talks -- the list looks endless, might not do them all. Organizers expected about 100 people, got more than 200...

UPDATE: the first lightning talks: Open Spaces (weird, not sure I got it), a lovely chap trying to convert the Hansard (which is getting XML already) in RDF, Jeff Tupholme on putting javascript inside python (crazy) within LiveConnector.

UPDATE: pydoctor statically analyses code to generate docs and then uses a pseudo-wiki interface to correct typos and generate diffs (sounds nice); a lexer parsing thing which went over my head; a freakily-dressed guy from ACCU on how to pitch Python to C(++) shops (use "high-level"!); Software Freedom Day next week (eek! I'm in Oslo)!

Labels: , , , , , , , , , , ,

posted by GiacomoL @ 11:18 AM   0 comments links to this post

23 August 2007

PyConUK 2007 update

The full schedule of tutorials and talks at PyconUK 2007 has just been posted. Yay! Anyone from Manchester going? I'm currently thinking of using the train, but I'd happily share car costs with someone else.

I'm probably going to see this list of talks: Saturday

Sunday

Looks like it's going to be a fantastic weekend!

Labels: ,

posted by GiacomoL @ 10:11 AM   2 comments links to this post