Philipp von Weitershausen wrote:

...hence the quotes. It's a "function" in that I want to use it as an adapter that doesn't need to be instantiated by a factory before being used.

All adapters need to be instantiated.

Why?

def myStrAdapter(something):
   return str(something)

This function adapts strings to integers, why would it need to be instantiated?

No. You always register a factory which is called upon lookup. That's because adapters are context-dependent and thus need to be instantiated every time you look them up.

What if they're not context-dependent as in my example above?

ultimately, I'm looking to replace code like the following:

convertors = {
  int:{str:str,datetime:datetime},
  str:(int:int,datetime:datetime},
}

def convert(x,y):
   return convertors[type(x)][type(y)](x)

...if you see what I mean. Apologies for the trivial examples, but these are real problems...

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
           - http://www.simplistix.co.uk

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to