首页 > 解决方案 > 如何在 cython 结构中创建日期时间字段?字符串字段怎么样?

问题描述

如何在 cython 结构中创建日期时间字段:

cdef struct Purchase:
    int purchase_id
    datetime purchase_timestamp
    str free_text

我应该用什么来表示上面的“日期时间”标识符?

字符串呢?我可以只使用“char *”吗?有更灵活的东西吗?如果我删除 Purchase 类的一个实例,我是否需要进行任何内存清理?

谢谢!

标签: pythoncython

解决方案


from cpython.datetime cimport datetime

cdef class Purchase:
    cdef int purchase_id
    cdef datetime timestamp
    cdef str free_text

推荐阅读