1

我正在编写 python 脚本,并且正在使用 python 日志记录模块将一些信息写入日志文件(请参阅http://docs.python.org/howto/logging.html)。

这是一个小例子(也来自提到的页面):

import logging
import logging.config

logging.config.fileConfig('logging.conf')

# create logger
logger = logging.getLogger('simpleExample')

# 'application' code
logger.info('info message')
logger.error('error message')

现在我想为 python 创建一个 c 扩展,我想在我的程序中导入它。

问题是:如何从我的 c 代码在我的日志文件中写入信息?有没有办法使用 python c 扩展中的日志记录模块?

感谢您的任何评论!

4

1 回答 1

2

“非常高级的 C API”有许多用于从 C 执行纯 python 代码的工具。从查看http://docs.python.org/c-api/veryhigh.html#PyRun_String开始。

于 2011-10-19T18:54:39.830 回答