def get_generic_name():
# may need to make this a search for the first non-kdllib reference
# make generic name from highest calling context
prev_function_name = None
for i in range(len(inspect.stack())):
(frame, filename, line_number,
function_name, lines, index) = inspect.stack()[i]
#print(frame, filename, line_number, function_name, lines, index)
# Use stack to get easier function name than parsing the code itself
if i > 0:
_, _, _, prev_function_name, _, _ = inspect.stack()[i - 1]
else:
prev_function_name = function_name
script_name = filename.split(os.sep)[-1]
lib_location = os.path.realpath(__file__)
lib_name = lib_location.split(os.sep)[-1]
# cover .py and .pyc
if script_name != lib_name and script_name != lib_name[:-1]:
name = script_name + "_" + prev_function_name
#print(frame, filename, line_number, function_name, lines, index)
return name
raise ValueError("Issue in generic name getter")
# Many of these from Ishaan G.
评论列表
文章目录