Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import sys 

2 

3def lookup_attr(obj, key): 

4 try: 

5 return getattr(obj, key) 

6 except AttributeError: 

7 exc = sys.exc_info()[1] 

8 try: 

9 get = obj.__getitem__ 

10 except AttributeError: 

11 raise exc 

12 try: 

13 return get(key) 

14 except KeyError: 

15 raise exc