Re: internal error
Bram Moolenaar <[email protected]> Sun, 18 Dec 2005 14:35:19 +0100
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
Calmar wrote:
> > > It seems aap lets python evaluate a variable that does not
> > > exist: _no.test_title
> >=20
> > Well, this happens in the eval() call, which is a Python function. T=
hus
> > you get a Python error message.
> >=20
> > We could make an exception for errors in Scope.py, since this is
> > probably a variable that doesn't exist. Try this patch:
>=20
> Yeah, that patch catches it.
>=20
> There seems to be a bad(probably good anyway?) thing about it:
>=20
> tmpstring =3D _no.$(match)_title
> @try:
> @ title =3D eval(_no.tmpstring)
> @except:
> @ title =3D ""
> :print $title
>=20
> 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:
>=20
> @if not hasattr(globals(), 'tmpstring'):
> @ print "variable is not defined"
>=20
> 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.
>=20
> 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.
--=20
Every person is responsible for the choices he makes.
/// Bram Moolenaar -- [email protected] -- 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 /=
//
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick