[Python-Dev] PEP 463: Exception-catching expressions
Antoine Pitrou
solipsis at pitrou.net
Sat Feb 22 11:35:39 CET 2014
More information about the Python-Dev mailing list
Sat Feb 22 11:35:39 CET 2014
- Previous message: [Python-Dev] PEP 463: Exception-catching expressions
- Next message: [Python-Dev] PEP 463: Exception-catching expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On sam., 2014-02-22 at 19:29 +0900, Stephen J. Turnbull wrote: > Antoine Pitrou writes: > > > Well, the only way to know that a key (or attribute) exists is to do > > the lookup. What else would you suggest? > > Do the lookup at the C level (or whatever the implementation language > is) and generate no exception, of course. That's what would make it > possibly more efficient. Let's see: - hasattr() does the lookup at the C level, and silences the AttributeError - dict.get() does the lookup at the C level, and doesn't generate an exception So apart from the minor inefficiency of generating and silencing the AttributeError, those functions already do what you suggest. Regards Antoine.
- Previous message: [Python-Dev] PEP 463: Exception-catching expressions
- Next message: [Python-Dev] PEP 463: Exception-catching expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list