Add a function to return just the line number of a code object.

This commit is contained in:
Guido van Rossum 1992-03-27 15:13:08 +00:00
parent c341c62e81
commit cb7ce349e2
2 changed files with 18 additions and 0 deletions

View 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

View 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