You can sort of do this with type (and this probably makes python purists really angry, but I've done similar once or twice):
def make_window(x1, x2):
lo, hi = sorted( (x1, x2) )
window = type('Window', (object,), {
'__call__' : lambda _, x: lo <= x <= hi,
'__repr__' : lambda _: '<%s..%s>' % (lo, hi)
})
return window()
That's actually making a new class called 'Window', inheriting from object, with a call and a repr special method. I still haven't personally decided whether it's gross or not, but I am pretty sure it's not pythonic.