Apr 8

Proxy modules in python

Here we have a module that proxies another.
The proxied module:

# module: b
a_list = [ 'a','b','c']

def print_list():
print a_list

The proxying module:

#module: a
from b import *

The user’s script:

#/usr/bin/python -tt
import a

print a.a_list
a.a_list=[]
print a.a_list
a.print_list()

Now when we run it:

$ python run.py
['a', 'b', 'c']
[]
['a', 'b', 'c']

The second list shows we successfully modified a.a_list to []. But then [...]


Oct 28

Worsterer, but not a GUI problem, per se.

The thing is, if it KNOWS how to do it, why doesn’t it just do it that way?


Aug 29

More on Makefiles

I posted before about Makefiles when a tool builds multiple targets, and some discussion was had. Further to that, a colleague found this cute solution and we refined it a little. It has several advantages over the last method I put forward:

It doesn’t require an additional file to be written to disk
It’s clearer [...]


Aug 4

Makefile when a tool creates multiple targets

Say one stage in your build process is a tool that writes out a series of source files and config files. You might have a rule that looks a bit like this:
glue.c glue.h net_conf.xml error_list.config: application.config context.xml target.conf
generate_glue.exe $^
The trouble is, this is exactly the same [...]


May 27

Special Feature for Disability-impaired Users

or, “HELP11 SHIFT IS STUCK ON1″.
If you do not have trouble typing, nor holding down shift while pressing other keys, then you probably don’t need Windows XP’s Accessibility features. If you habitually tap the shift key whilst you consider your next sentence, for example, then you are definitely better off without them.
Tapping shift in [...]


May 23

So Much For Probability

Turns out it wasn’t safe to suggest I would never implement it.

There’s the C# express edition source there and also an executable. It saves and loads its data in the current directory, so I recommend running it via a shortcut so you can control where it puts its datafile.
It’s clear it needs lots of [...]


May 22

Automatically Identify User

This is an idea that occured to me around about 1992. It’s probably safe to suggest I will never implement it.
By catching all keydown events (importantly, including shift and ctrl), the “flavour” of someone’s typing can be recorded. We have a set of pairs of keys, and the delay between them. [...]


May 19

Lunchtime



Mar 7

demacs

Having learned that bash (or readline) uses emacs-like keybindings to move cursors around, and having problems going to start-of-line or end-of-line by pressing HOME and END when sshed to the Mac, I googled for emacs key bindings and stumbled upon Emacs Makes You Retarded. If you can’t be bothered to read the article, basically [...]


Feb 19

Partially Instantiate Python Template Strings

"""
    Template Dictionary module
    
    An enhancement to python's template stuff.  At present you must supply all
    parameters to instantiate a string template.  We want to be able to 
    instantiate only the paramaters that we have right now, and leave the 
    others for instantiation later.
    
    Without TDict:
    
    >>> "%(greeting)s %(person)s"%{'greeting': 'Hello', 'person': 'World'}
    'Hello World'
    >>> "%(greeting)s %(person)s"%{'greeting': 'Hello'}
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError: 'person'    
    
    This module provides class TDict (template dictionary) that, if you try 
    to read a non-existent key "keyname", returns "%(keyname)s".  Hence, it
    "passes through" any undefined names.
    
    >>> from TDict import *
    >>> a=TDict({})
    >>> a['a']='bibble'
    >>> a['a']
    'bibble'
    >>> a['b']
    '%(b)s'
    >>> "%(greeting)s %(person)s"%TDict({'greeting': 'Hello'})
    'Hello %(person)s'
    >>> tdict("%(greeting)s %(person)s",{'greeting': 'Hello'})
    'Hello %(person)s'
    
"""

class TDict(dict):
    
    def __init__(self,d={}):
        dict.__init__(self)
        for k in d.keys():
            self[k]=d[k]
    
    def __getitem__(self, key):
        try:
            return dict.__getitem__(self, key)
        except KeyError:
            return "%%(%s)s"%key

def tdict(template,dict):
    d=TDict(dict)
    return template%d


 

March 2010
S M T W T F S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031  

Archives

Meta