Add a function to return just the line number of a code object.
This commit is contained in:
parent
c341c62e81
commit
cb7ce349e2
@ -52,3 +52,12 @@ def getcodename(co):
|
|||||||
|
|
||||||
def getfuncname(func):
|
def getfuncname(func):
|
||||||
return getcodename(func.func_code)
|
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
|
||||||
|
@ -52,3 +52,12 @@ def getcodename(co):
|
|||||||
|
|
||||||
def getfuncname(func):
|
def getfuncname(func):
|
||||||
return getcodename(func.func_code)
|
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…
x
Reference in New Issue
Block a user