Python Programming, news on the Voidspace Python Projects and all things techie.

#70

See You All Later

Razz That's it... I'm off to Romania. Have a good time while I'm away.

I've ransacked IT conversations for lots of interesting interviews to listen to. If I find any gems I'll let you know...

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2005-07-08 16:14:50 | |

Categories: ,


#69

Round Tripping

Surprised I've made a huge amount of progress on the new ini file round tripper - ConfigObj 4. It now reads and writes config files with nested sections [1].

One of the nicest features is the way it will interface to a validation schema that will let you specify the type of each expected value. It will also convert the value into that type (as well as checking it conforms to that spec).

ConfigObj 4 in Subversion

Of all the config file readers I've seen it has the nicest programmers interface, and I like the syntax for writing config files. For example the way you write list values.

For once in my life I've written quite a few tests - one of them even revealed a bug Wink . At the moment they mainly serve as examples of how to use it.

The writein methods, preserving comments, and the changes to the validation system are all that need completing - plus of course documentation.

Python 2.2

It is also now Python 2.2 compatible. The main reason I want it to stay compatible with Python 2.2 is that I'm poor Very Happy . A lot of my scripts run as CGIs on cheap shared hosting accounts. This is probably not about to change.

I used Movable Python to check compatibility with 2.2 - it wasn't Crying or Very sad . There were two reasons it wasn't compatible :

  1. I kept forgetting that if you use constructs like if val in some_string: then val can only be a single character.
  2. There's no real boolean type in Python 2.2 - this means things like if val is True: don't work. Although val may well evaluate to True, it doesn't have the identity of True. It's easy enough to sort - you just use if val: instead... it's just less readable, marginally slower, and meant changing a lot of code Rolling Eyes .

Attributes or Members

One of the things I had to decide for ConfigObj was the programmers interface to the data [2]. ConfigParser makes you call a method (a getter) to retrieve data. This is part of reasons that so many other people have written alternative config parsers.

For convenience - almost all of them have opted to provide attribute access to the values of the config file. The values are mapped to attributes of your config object (buy overloading __getattr__ and __setattr__. I think this is unpythonic, and that subclassing dict is a much better way. This is for these reasons :

  1. Some values can't be attributes. For example print can't be used as an object attribute. This means you have to provide a getter as well. This violates there should be only one obvious way to do it.
  2. A config file, and it's sections, is a set of keywords mapping to values. This means a mapping object is a very good representation of it. (In fact it's a sequence of mappings - so ConfigObj is actually now an ordered dictionary that keeps to the sequence of the values).
  3. A dictionary has nice built in ways to iterate over it (and methods like get that allow you to specify defaults). I've overloaded most to stick to the sequence (and allow you to change the sequence) - but it's an interface all Python programmers are familiar with. If you use attributes you couldn't iterate over the attributes because of all of the methods etc...
  4. If you use attributes to represent the data then you are mixing your methods and real attributes with the data. Leave your object attributes as attributes, and your data as members.

Footnotes

[1]And multiline values, list values, and all the other wonderful features Cool .
[2]It's actually a decision I made a while ago - but I wanted to record my reasons.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2005-07-08 09:19:59 | |

Categories:


#68

Shhhh.....

emoticon:carrot Hmm.. I've been a bit quiet recently. I'm also about [1] to fly out to Romania for a week, to visit the in-laws - so it will be quiet for a little while yet.

The good news is that the long awaited ConfigObj revamp is nearly complete. It already reads config files with nested sections - to an arbitrary depth, using indentation for nesting. It now has a working write method, and an interface to validate.py. This allows you to easily write full validating schema for your config files. It has a very nice programmers interface, and the config file syntax is also nice and simple - no pseudo XML junk [2].... There's not much left to do [3] and you can pull the latest version out of SVN. I haven't written new docs (yet) - but for once in my life I've done a barrage of tests that also illustrate most of the functionality.

I've just started using the enigmail plugin for the Thunderbird email program. It provides military grade encryption and digital signing for emails, using openPGP [4]. Very nice Cool . I've started using it because a guy called Nicola Larosa is working on a coding project with me - and he wants my emails signed Confused - so there you go. Very cyberpunk Cool .

Quote of the week from the TBS IT manager, when asked how to solve a printing problem :

"Uhm... write it down ?"
[1]Well - on Saturday anyway.
[2]It uses a simple 'INI' file type syntax. Very easy to read/write.
[3]The writein method needs implementing, and comments aren't yet preserved. Everything else works fine.
[4]It's actually a bit easier to use on windoze with the GnuPT client.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2005-07-06 11:16:26 | |

Categories:


Hosted by Webfaction

Counter...