mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Add a function to return just the line number of a code object.
This commit is contained in:
parent
c341c62e81
commit
cb7ce349e2
2 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue