【发布时间】:2015-06-08 04:57:51
【问题描述】:
我有一个简单的 python3 脚本,当我从控制台运行它时可以工作:
import configparser
file = 'config_test.ini'
config = configparser.ConfigParser()
config.read(file)
for key in config['test_section']: print(key)
调用的ini文件如下所示:
[test_section]
testkey1 = 5
testkey2 = 42878180
testkey3 = WR50MS10:1100012307
testkey4 = WR50MS04:1100012010
testkex5 = 192.168.200.168
脚本运行良好并返回ini文件的五个键。
不,我通过以下方式将其配置为每分钟 cronjob(在 Raspberry Pi 上的 rasbian 上运行):
* * * * * python3 /home/pi/s0/testconfig.py >> /tmp/cron_debug_log.log 2>&1
日志如下所示:
Traceback (most recent call last):
File "/home/pi/s0/testconfig.py", line 7, in <module>
for key in config['test_section']: print(key)
File "/usr/lib/python3.2/configparser.py", line 941, in __getitem__
raise KeyError(key)
KeyError: 'test_section'
有谁知道我做错了什么 亲切的问候
【问题讨论】:
标签: python-3.x cron configparser