![](https://secure.gravatar.com/avatar/2e9b5cb8fcf834ddf8be44a450efe97f.jpg?s=120&d=mm&r=g)
Mary Gardiner wrote:
What's a good way for the Page object to wrap that dictionary that doesn't involve doing this:
def data_name(self, ctx, data): return self.d['project_name']
...
I vaguely recall that the equivalent of this used to be possible in Woven:
def data_project(self, ctx, data): return self.d
and then that the data items were accessible by (say) stan.directive("project/project_name"). This doesn't look like its supported in Nevow. Is this correct? What alternative designs are there for something like this?
heya Mary, there's a lot of Nevow magic I don't know, but in case something doesn't exist, something like the following should work, albeit, pretty crude: python -c ' class C: def __getattr__( self, attr ): if attr.startswith( "data_" ): return lambda ctx, data, s=self, a=attr : s.d["project_%s" % a[len("data_"):]] raise AttributeError c = C() c.d = { "project_name" : "roar" } ctx = "ned" data = "fred" print c.data_name( ctx, data ) ' Andy.