Python 调试打印变量名

python 在调试过程中需要打印变量名称和打印变量值, 下面代码可以实现:

def tiaoshi(name, locals):    
    # print(locals)
    for key in locals:
        if locals[key] == name:
            print(key)     
    print(name)
    input()
	
def main():

    a = '999'
    tiaoshi(a,locals())	

if __name__ == '__main__':
    main()


这样就可以输出:
a
999

你可能感兴趣的:(python)