我正在处理一个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-extension,我想在我的程序中导入它。
问题是:如何从我的c代码中在我的日志文件中写入信息?有没有办法从python c-extension中使用logging-module?
感谢您的任何评论!
答案 0 :(得分:2)
“非常高级的C API”有许多用于从C执行纯Python代码的工具。首先查看http://docs.python.org/c-api/veryhigh.html#PyRun_String。