Posts about python (old posts, page 2)

2003-10-09 19:41

Nifty python/xmlrpc thing

Using python, it's trivial to turn any module into a XMLRPC server. So, if you are careful writing your app in a modular way, you can move the backend elsewhere in very little code.

For example, if I had a module that has some functionality, like this (

#Stupid simple module

def add(a,b):
        return a+b

A program would use it like this:

import module
print module.add(2,4)

Now, if I move the module to a remote box (server), create this xmlrpc server program in the server (and run it ;-):

#!/usr/bin/env python

#Simple generic XML-RPC server

import module

import SimpleXMLRPCServer

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 800


And this bridge module in the client (

import xmlrpclib

server = xmlrpclib.Server('')

Now this very slightly modified version of our program works in exactly the same way as the original:

from clientmodule import server as module

print module.add(2,4)

Of course this has issues:

  • It has no security
  • XMLRPC could introduce errors and the program doesn't catch them.
  • It could be made even more transparent with some more pythoning

But anyway, I think it's cute.

2003-10-06 16:56

Bartleblog now in

So, the link below will disappear in a minute or two. Right now, you can get it via CVS.

2003-10-05 17:57

Bartleblog 0.0.1

I got a few mails asking to see Bartleblog... well, if you have a working PyQt, and a working PyDS (advogato support is totally broken right now), and you have a good backup of your blog, then you may try to get it from here (Use CVS)

It is just not useful for a normal blogger right now.

I hope the nice guys at don't mind me posting it here (it's smaller than some of the dynamic HTML pages ;-)

In a couple of days I will move it to, as soon as I get the project approved.

2003-10-05 17:34

klog == bartleblog

I wonder if bartlebog is a good name. It sure is better than klog, and I like XIXth century lit references.

I also suspect almost noone will get it, and that it just can't be pronounced ;-)

I wanted it to be bartleby, but there is some tool using that name in sourceforge.

On other issues: it's HOT here!.

2003-09-30 21:52

Baby steps

Implementing proper updating is simple in that sending stuff to PyDS is simple. However, having the GUI do the right thing is tricky:

When you modify an entry and switch to another, you have to offer a chance to save or discard.

If the user discards, you have to go back to the original data, so it must be saved somewhere else. And remember this:

>>> a={}
>>> b=a
>>> a['x']=1
>>> b['x']

Yeah, obvious python semantics. Lost an hour, though ;-)

What you want to do instead is:


If he saves, you have to upload.

Also, when he modifies, you have to update the post list realtime, so you see a coherent entity. Not too hard, but it forces you to despaghettize code somewhat.

2003-09-29 22:15

Almost a useful app

Lacks lots of stuff, but the UI is pretty much done.

Stuff needed before publishing:

  • Updating posts (PyDS and advogato)
  • Deleting posts (PyDS and advogato)
  • Posting new (advogato)

Stuff done:

  • Account creation
  • Account edition
  • Post edition
  • Posting new (PyDS)
Sadly, I have lots of work for the next two or three days, so progress will slow.

And.... evil plugin code! (I will redo it someday, maybe):

#Here acctype is one of "pyds" or "advogato"
#Both are modules that define a class called Editor, 
#which inherits a QWidget

exec ("import "+acctype+" as blog")

Of course, if an evil guy could redefine the list of plugins and insert an evil module into your PYTHONPATH, this would REALLY suck ;-)

2003-09-28 19:22

Now, that was easy!

I always dread the moment when a package has to be shared, and something distributable has to be made. You know, don't forget any files, and such.

Not to mention the ancillary nightmare of make/automake/autoconf/aclocal/etc. I simply trusted the kindness of strangers for that.

And I never managed to make RPMs or anything like it. But distutils makes installing, distributing, really simple.

Here's an example:
#!/usr/bin/env python

from distutils.core import setup

setup (name="klog",
       description="klog: a PyQt blog tool",
       author="Roberto Alsina",
       author_email="[email protected]",
       long_description="""Long description here """


That is enough to build, install, create RPMs, Debian packages, include the file in PyPI, and who knows what else.

Have another file in the project? Just toss it in the klogmodules directory, and it's done!

Of course this is only for python apps, but I don't see me coding in other languages soon. The only reason I got into C++ was because there was no decent interpreted language with a decent toolkit!

2003-09-28 04:37

Second klog post ever

Ok, klog is just a temporary name, but it's 4AM, and I am not creative. So, what is it? It's a PyQT client to PyDS.

Look at the picture in the link, if you want!

Now, I am not sure if I will work on it much, since I only did it to learn a bit about XMLRPC, but it DOES work, or else, you won't be able to read this anyway ;-)

Rationale: While PyDS is a great piece of work, editing text through a web page feels like scratching wearing gloves. It is doable, but it's not satisfying. So, I tried this just to see how hard it would be... answer: not very hard, really.

Just to keep me honest, and keep the software somewhat designed instead of piled, I am doing a advogato module that replaces the PyDS one (of course with much less functionality).

Contents © 2000-2018 Roberto Alsina