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

后端 未结 6 1174
没有蜡笔的小新
没有蜡笔的小新 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:54

    The Rod solution is perfectly usable. It could be even extended to handle many vars. But you can get close to that with much less magic:

    def dd(**kwargs):
        print ", ".join(str(k) + "=" + str(v) for k, v in kwargs.iteritems())
    
    a = 1
    dd(a=a,b=3)
    

    output:

    a=1, b=3
    

提交回复
热议问题