From: Guido van Rossum Date: Fri, 27 Mar 1992 15:13:08 +0000 (+0000) Subject: Add a function to return just the line number of a code object. X-Git-Tag: v0.9.8~460 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cb7ce349e26e5c513966ff6ec6002e2f696b81f1;p=thirdparty%2FPython%2Fcpython.git Add a function to return just the line number of a code object. --- diff --git a/Lib/codehack.py b/Lib/codehack.py index 8a4f611696de..d00d2bfec9ce 100644 --- a/Lib/codehack.py +++ b/Lib/codehack.py @@ -52,3 +52,12 @@ def getcodename(co): def getfuncname(func): return getcodename(func.func_code) + +# A part of the above code to extract just the line number from a code object. + +def getlineno(co): + code = co.co_code + if ord(code[0]) == SET_LINENO: + return ord(code[1]) | ord(code[2]) << 8 + else: + return -1 diff --git a/Lib/lib-old/codehack.py b/Lib/lib-old/codehack.py index 8a4f611696de..d00d2bfec9ce 100644 --- a/Lib/lib-old/codehack.py +++ b/Lib/lib-old/codehack.py @@ -52,3 +52,12 @@ def getcodename(co): def getfuncname(func): return getcodename(func.func_code) + +# A part of the above code to extract just the line number from a code object. + +def getlineno(co): + code = co.co_code + if ord(code[0]) == SET_LINENO: + return ord(code[1]) | ord(code[2]) << 8 + else: + return -1