制作封闭单元格的简单方法是进行封闭:
def make_cell(val=None): x = val def closure(): return x return closure.__closure__[0]
如果要重新分配现有单元格的内容,则需要进行C API调用:
import ctypesPyCell_Set = ctypes.pythonapi.PyCell_Set# ctypes.pythonapi functions need to have argtypes and restype set manuallyPyCell_Set.argtypes = (ctypes.py_object, ctypes.py_object)# restype actually defaults to c_int here, but we might as well be explicitPyCell_Set.restype = ctypes.c_intPyCell_Set(cell, new_value)
当然,仅CPython。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)