Can you translate this debugging macro from C++ to python?

后端 未结 6 1172
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 03:06

I use this very helpful macro when developing in C++:

#define DD(a) std::cout << #a \" = [ \" << a << \" ]\" << std::endl;std::cout.f         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-15 03:43

    You can't get a variable (well, object)'s name in python. But you can pass the object's name to get its value (kinda the opposite of what you do with that macro)

    >>> a=4
    >>> locals()['a']
    4
    

    EDIT: a detailed explanation may be found here

提交回复
热议问题