KeyError with non-existant _[variables]
I'm getting a KeyError trying to render non-existant _[variables] <dtml-var "_[variable]" null="triedthis" missing="triedthistoo"> say variable == firstname, but firstname is not a variable- I'd like to set it to null and proceed- { I'm using this to build a generic SQL edit form based on column names and keyed input } Chas. <c3w@ISP.NET> ISP Networks, Inc.
I'm getting a KeyError trying to render non-existant _[variables]
<dtml-var "_[variable]" null="triedthis" missing="triedthistoo">
Why not just do: <dtml-var variable null="triedthis" missing="triedthistoo"> ? To be honest, though, I've bumped into this a lot and I do wish namespaces had a get method like dictionaries: _.get(name,default) ..so you can get around this sort of thing. Hehe... here's the implementation: _marker=[] def get(self,name,default=_marker): try: return self.__getitem__(name) except KeyError: if default is not _marker: return default raise ...could someone add it in or should I stick it in the collector? cheers, Chris
Couldn't you do: "_.getattr(_,variable,_.None)" to get the desired result? --- Chris Withers <chrisw@nipltd.com> wrote:
I'm getting a KeyError trying to render non-existant _[variables]
<dtml-var "_[variable]" null="triedthis" missing="triedthistoo">
Why not just do: <dtml-var variable null="triedthis" missing="triedthistoo"> ?
To be honest, though, I've bumped into this a lot and I do wish namespaces had a get method like dictionaries:
_.get(name,default)
..so you can get around this sort of thing.
Hehe... here's the implementation:
_marker=[]
def get(self,name,default=_marker): try: return self.__getitem__(name) except KeyError: if default is not _marker: return default raise
...could someone add it in or should I stick it in the collector?
cheers,
Chris
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists -
http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
===== | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `-----------------> __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/
Casey Duncan wrote:
Couldn't you do:
"_.getattr(_,variable,_.None)"
to get the desired result?
If _.item===_['item'], then yes, btu I wasn't aware that was the case. If it is, how would I get something called 'getitem', for example, from the namesapce, use the _. notation? cheers, Chris
Casey Duncan writes:
Couldn't you do:
"_.getattr(_,variable,_.None)"
to get the desired result? I would not expect this:
"getattr" accesses the attributes of "_", such as "string", "int", ... It can not access the "content" exposed by the mapping interface (e.g. via __getitem__). A "get" method would also allow to pass "_" as parameter to Z SQL methods. I called for it a long time ago. But, helas ... Dieter
participants (4)
-
Casey Duncan -
Chas Wareing -
Chris Withers -
Dieter Maurer