小编M. *_*ber的帖子

没有null的语言的最佳解释

当程序员抱怨空错误/异常时,有人经常会问我们做什么而没有null.

我对选项类型的酷感有一些基本的想法,但我没有最好的表达它的知识或语言技巧.对于普通程序员可以接近的方式写的以下内容有什么好的解释,我们可以指出那个人?

  • 默认情况下,引用/指针的不可取性是可以为空的
  • 选项类型的工作原理包括简化检查空案例的策略
    • 模式匹配和
    • monadic理解
  • 替代解决方案,如消息吃零
  • (我错过了其他方面)

null programming-languages functional-programming nullpointerexception non-nullable

223
推荐指数
7
解决办法
4万
查看次数

跟踪时获取 python 内置函数的返回值

通过使用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)

python debugging trace profiling

5
推荐指数
0
解决办法
452
查看次数