]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add a function to return just the line number of a code object.
authorGuido van Rossum <guido@python.org>
Fri, 27 Mar 1992 15:13:08 +0000 (15:13 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 27 Mar 1992 15:13:08 +0000 (15:13 +0000)
Lib/codehack.py
Lib/lib-old/codehack.py

index 8a4f611696ded8280e5a189ac5b96fba43b89cc9..d00d2bfec9ce2417bd9e42279c4e0ec830f88663 100644 (file)
@@ -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
index 8a4f611696ded8280e5a189ac5b96fba43b89cc9..d00d2bfec9ce2417bd9e42279c4e0ec830f88663 100644 (file)
@@ -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