Mercurial > cpython-lru_cache-weakref
comparison Lib/codehack.py @ 723:e7571a18bdef legacy-trunk
Add a function to return just the line number of a code object.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 27 Mar 1992 15:13:08 +0000 |
| parents | a0d4c5ef1d5d |
| children | 1940892d2fe3 |
comparison
equal
deleted
inserted
replaced
| 722:57e94eba2484 | 723:e7571a18bdef |
|---|---|
| 50 | 50 |
| 51 # Use the above routine to find a function's name. | 51 # Use the above routine to find a function's name. |
| 52 | 52 |
| 53 def getfuncname(func): | 53 def getfuncname(func): |
| 54 return getcodename(func.func_code) | 54 return getcodename(func.func_code) |
| 55 | |
| 56 # A part of the above code to extract just the line number from a code object. | |
| 57 | |
| 58 def getlineno(co): | |
| 59 code = co.co_code | |
| 60 if ord(code[0]) == SET_LINENO: | |
| 61 return ord(code[1]) | ord(code[2]) << 8 | |
| 62 else: | |
| 63 return -1 |
