【发布时间】:2009-08-20 02:48:11
【问题描述】:
我正在尝试使用 python 的 ConfigParser 对象在我的 php.ini 文件中设置一个选项 (xdebug.profiler_enable)。这是代码: 我正在尝试修改 php.ini 文件中的部分
[xdebug]
;XDEBUG SETTINGS
;turn on the profiler?
xdebug.profiler_enable=0
xdebug.profiler_append=1
xdebug.profiler_enable_trigger=0
xdebug.trace_output_name="%R"
xdebug.profiler_output_dir="/home/made_up_user/www/cachegrind/"
Python
import sys
import ConfigParser
if __name__ == '__main__':
phpIniLocation = "/home/made_up_user/Desktop/phpinicopy.ini";
phpIni = ConfigParser.RawConfigParser();
phpIni.read(phpIniLocation);
xdebugSetting = phpIni.getboolean("xdebug", "xdebug.profiler_enable");
if xdebugSetting:
phpIni.set("xdebug", "xdebug.profiler_enable", "0");
else:
phpIni.set("xdebug", "xdebug.profiler_enable", "1");
环境: Ubuntu 9.04,蟒蛇 2.6 一切似乎都运行良好。 xdebugSetting 变量正确返回选项的布尔值,我可以解析该部分并检索每个选项的正确值,并且 set 方法不会引发任何异常,但是当我检查文件时,选项没有被更改。我使用了 RawConfigParser、ConfigParser 和 SafeConfigParser,结果都一样。该脚本以 root 权限运行。有什么我想念的吗?如何让 set 方法起作用?
【问题讨论】:
-
是什么让您认为配置解析器会更新配置文件?你在哪里读到的?
标签: python linux file-io ubuntu