durusmail: quixote-users: Have Publisher search keys as well as attributes?
Have Publisher search keys as well as attributes?
2002-09-11
2002-09-11
Have Publisher search keys as well as attributes?
Hamish Lawson
2002-09-11
What do folks think about the idea of having Publisher search a namespace's
keys (if available and assuming that the component has been named in
_q_exports) when it can't find a component among the namespace's
attributes? This would allow the use of component names that aren't valid
Python attributes, e.g. 'report.html', for a little less work than
resorting to _q_getname.

Writing the above has just prompted me to think about what would happen if
you attempted to supply setattr with an attribute name that wasn't a valid
identifier.

[Some experimentation later ...]

It turns out that supplying setattr with an attribute name that isn't a
valid identifier *does* set that attribute - you just have to use getattr
to get back at it, which is what Publisher does anyway. You can set a
non-identifier attribute for the current module by specifying
sys.modules[__name__] as the first argument to setattr.

So it's actually already possible to use non-identifier component names
without having to resort to _q_getname, thus removing one of my main
motivations for having Publisher search a namespace's keys. Is there any
remaining merit in the idea?


Hamish Lawson



reply