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

Cyberpunk Search Engine, and Other Stuff

emoticon:exclaim I've used the engine from Python Search [1] to create a search engine dedicated to Cyberpunk.

If you need to research anything related to the cyber-underground, or cyberpunk fiction, you need to be using Cyber Search.

It currently indexes around 600 domains - and so it only returns results from websites relevant to cyberpunk. If you have a website that you think ought to be included in the index, then use my Contact Form to let me know.

It uses Yahoo Web Services. When I've added a couple of features (like back and forward buttons) to it then I'll release it as a mini-project called skimpy.


In other news - work internet access has got a lot more restrictive (again). That means for a little while I may be updating a little less regularly. sigh

I've also made a decision about the future direction of my life (which you may hear more about soon). The fit might be gently deflecting from the shan as a result... double sigh

More positively, my urllib2 tutorial got a very complimentary mention in the Dr. Dobb's Python-URL! - thanks guys. Smile

[1]Python Search now has around 1300 domains that it searches. Again - I'd like to hear of any that I've missed.

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

Posted by Fuzzyman on 2005-11-18 09:47:57 | |

Categories: , , ,


rest2web 0.4.0 alpha

emoticon:html rest2web 0.4.0 alpha is now available for download. After about five months (and lots of changes), I've finally done a new release.

This means :

There have been lots of changes since 0.3.0.

The documentation has been greatly improved. The tutorial means that anyone wanting to use rest2web to create a site should be able to get up to speed on the basics very quickly.

You can see a sample output from the gallery over at Example Gallery.

[1]The gallery plugin will work as a standalone program to generate static html gallery pages.
[2]The gallery plugin doesn't yet work with the executable.

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

Posted by Fuzzyman on 2005-11-14 08:35:38 | |

Categories: ,


Mapping and Sequence Type Protocols

emoticon:film A while ago I did a blog entry ranting about duck typing in Python.

In it I suggested that we could create a useful definition of the MappingType and SequenceType protocols. This doesn't require anything as heavy duty as interfaces, but is more useful than the broken functions IsMappingType and IsSequenceType from the operator module.

Well - it's a simple protocol, but it could be useful anywhere you want to specify (as part of a library API) a dictionary like object or a sequence like object.

New IsType Functions

So we define a MappingType objects as one that has __getitem__ and a keys method.

We define a SequenceType object as one that has __getitem__ and doesn't have a keys method.

Below are two functions that implement a basic test for this protocol. The functions return True if the object you pass them appears to support the protocol.

Both functions also take an optional argument require_set. If this is True then the object must also have a __setitem__ method.

def IsMappingType(obj, require_set=False):
    """
    Returns ``True`` if an object appears to
    support the ``MappingType`` protocol.

    If ``require_set`` is ``True`` then the
    object must support ``__setitem__`` as
    well as ``__getitem__`` and ``keys``.
    """

    if require_set and not hasattr(obj, '__setitem__'):
        return False
    if hasattr(obj, 'keys') and hasattr(obj, '__getitem__'):
        return True
    else:
        return False

def IsSequenceType(obj, require_set=False):
    """
    Returns ``True`` if an object appears to
    support the ``SequenceType`` protocol.

    If ``require_set`` is ``True`` then the
    object must support ``__setitem__`` as
    well as ``__getitem__``.

    The object must not have a ``keys``
    method.
    """

    if require_set and not hasattr(obj, '__setitem__'):
        return False
    if (not hasattr(obj, 'keys')) and hasattr(obj, '__getitem__'):
        return True
    else:
        return False

Note

A string is a sequence, that means that IsSequenceType(a_string) returns True.

You can't assign to members of a string though (they're immutable). This means that IsSequenceType(a_string, require_set=True) returns False.

I suggest that if you need to differentiate between strings and other sequences (without using require_set), it's reasonable to test for string like objects using isinstance(obj, basestring).

Since Python 2.2, it doesn't really make sense to implement a string like object that isn't a subclass of str or unicode.

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

Posted by Fuzzyman on 2005-11-14 08:34:09 | |

Categories: , , ,


The Other Articles

emoticon:test_tubes I've had a good response to my tutorial on OOP - including someone wanting to translate it into Brazilian. Smile

A few hundred people have looked at it, I have no idea how many have actually read it of course. Wink

The irony is, that means that in the last few days more people have looked at that one article than have looked at my article index page. This has links to all my other Python/computer related articles - some of which are genuinely useful. Laughing

My website isn't particularly good at directing people there it seems. sigh

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

Posted by Fuzzyman on 2005-11-14 08:32:52 | |

Categories: , ,


Hosted by Webfaction

Counter...