当我运行以下代码时:
def month_1():
return 'January'
def month_2():
return 'February'
def to_months(argument):
switcher = {1:month_1,2:month_2}
func = switcher.get(argument,
lambda: " Error found!")
return func
address = id(to_months(1))
print(ctypes.cast(address,
ctypes.py_object).value)
我明白了:
“ function month_1 at 0xf58abc48”
代替此:
“一月”
如何获取函数的返回值而不是函数的地址?
如果我做了这样的事情:
df = 5
fg = id(df)
print(ctypes.cast(fg,
ctypes.py_object).value)
我会得到这个:
'5'
而不是值的地址