You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importinspectdefvarname(var):
""" Gets the name of var. Does it from the out most frame inner-wards. :param var: variable to get name from. :return: string """forfiinreversed(inspect.stack()):
names= [var_nameforvar_name, var_valinfi.frame.f_locals.items() ifvar_valisvar]
iflen(names) >0:
returnnames[0]
Usage
defchk_10(arr):
chk=0foriinrange(len(arr)-1):
ifarr[i+1] -arr[i] <10:
print('in {}, index={}, value={}'.format(retrieve_name(arr), i, arr[i]))
chk+=1print('in {}, total {} points error.'.format(retrieve_name(arr), chk))
chk_10(seq0)