At 08:51 AM 2/10/04 -0800, Guido van Rossum wrote: > > Why was Python syntax designed so > > except (TypeError, ValueError): > > is OK but > > except [TypeError, ValueError]: > > is forbidden. Should this be changed? Is immutability needed here? Where > > in Python is immutability really needed or really improves efficiency? > >I never *intended* this to be seen as a container, but rather as a use >of parentheses for grouping. But the current implementation *does* have a nice side effect of allowing error psuedoclasses to be created, e.g.: FooOrBarError = FooError, BarError try: ... except FooOrBarError: ... This can be useful for dealing with stuff like DBAPI errors, where you're writing code that may need to work with multiple DBAPI modules' errors simultaneously. Since FooOrBarError can be rebound to reflect the possible errors in play, it allows some dyanmism without having to write a bunch of Python code to introspect sys.exc_info(), while also making the code's intention clearer than if it had to do such introspection.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4