当程序员抱怨空错误/异常时,有人经常会问我们做什么而没有null.
我对选项类型的酷感有一些基本的想法,但我没有最好的表达它的知识或语言技巧.对于普通程序员可以接近的方式写的以下内容有什么好的解释,我们可以指出那个人?
null programming-languages functional-programming nullpointerexception non-nullable
通过使用sys.setprofile (profilefunc),我不仅可以跟踪常规 Python 函数,还可以通过事件“c_call”和“c_return”跟踪内置函数,但我找不到获取内置函数的返回值的方法。
对于常规函数,arg传递给 profilefunc 的参数 指的是返回值(如果event等于“return”)。但是,如果event等于“c_return”,arg则为 C 函数对象。
是否有另一种方法来检索内置函数的返回值?也许通过从帧中提取最后返回的值?
这是一个最小的例子:
import sys
import numpy as np
from types import FrameType
def tracefunc(frame: FrameType, event: str, arg):
if event == 'call':
func_name = frame.f_code.co_name
print(f'Call_to {func_name}')
elif event == 'return':
func_name = frame.f_code.co_name
print(f'Return_from {func_name}, returning {arg}')
elif event == 'c_call':
func_name = arg.__name__
print(f'Call_to_builtin {func_name}')
elif event == 'c_return':
func_name = arg.__name__
print(f'Return_from_builtin {func_name}, returning ???')
return tracefunc
if …Run Code Online (Sandbox Code Playgroud)