Re: [A-A-P-develop] internal error
Brought to you by:
vimboss
From: Bram M. <Br...@mo...> - 2005-12-18 13:33:48
|
Calmar wrote: > > > It seems aap lets python evaluate a variable that does not > > > exist: _no.test_title > > > > Well, this happens in the eval() call, which is a Python function. Thus > > you get a Python error message. > > > > We could make an exception for errors in Scope.py, since this is > > probably a variable that doesn't exist. Try this patch: > > Yeah, that patch catches it. > > There seems to be a bad(probably good anyway?) thing about it: > > tmpstring = _no.$(match)_title > @try: > @ title = eval(_no.tmpstring) > @except: > @ title = "" > :print $title > > that does not work anymore, because the error gets catched. When I try this the "except:" part is done, which is what was intended, right? Note that it's not good to use try/except this way, because any typing mistakes go unnoticed. > I think there is another way, to check if a variable exists: > > @if not hasattr(globals(), 'tmpstring'): > @ print "variable is not defined" > > That would work with checking for globals, but I think I would > need to check for the _no namespace? On #python they told me > something about dir(obj) but I can't get it to work. > > How could I check if a variable is 'defined' without the @try: > @except: since that don't seems to work anymore with your patch? You can use has_key(): @if _no.has_key("varname"): The scopes behave like dictionaries. This does require you to split the scope from the variable name. -- Every person is responsible for the choices he makes. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://www.ICCF.nl /// |