草庐IT

python - 如何更改 Python 函数的表示?

>>>defhehe():...return"spam"...>>>repr(hehe)''我想要:>>>repr(hehe)'hehefunctioncreatedbyawesomeprogrammer'我该怎么做?将__repr__放在hehe函数中不起作用。编辑:如果你们想知道我为什么要这样做:>>>defaultdict(hehe)defaultdict(,{})我只是不喜欢它在这里显示的方式。 最佳答案 不,您不能更改函数对象的表示;如果你想添加文档,你会添加一个文档字符串:deffoo():"""Frobthebarba