配置文件错误
Config file error
我已经为我的 python 程序创建了一个配置文件。配置文件包含我使用 'i2cset' 模块的变量。如下所示:
这是我的配置文件,名为'try.ini'
[new]
a = ('i2cset', '-y', '0', '0x20', '0x14', '0x01')
我从我的主要代码中读取如下:
from ConfigParser import SafeConfigParser
parser=SafeConfigParser()
parser.read('try.ini')
def set21(tog=[0]):
tog[0]= not tog[0]
if tog[0]:
set0.config(text='p21_1')
A=parser.get('new', 'a')
subprocess.call(''.join(A), shell=True)
else:
set0.config(txt='p21_0')
但每次我执行主程序时都会收到一条错误消息:
/bin/sh: 1: 'i2cset ': not found.
我不知道为什么会这样。当我 运行 程序没有配置文件时,它执行得很好......
有人可以帮忙吗..
亲切的问候,
纳米塔.
您的错误在于 .ini 文件的语法。
[new]
a = ('i2cset', '-y', '0', '0x20', '0x14', '0x01')
您希望变量 a
被读取为一个元组,而它实际上是一个包含 "('i2cset', '-y', '0', '0x20', '0x14', '0x01')"
.
的字符串值
我已经为我的 python 程序创建了一个配置文件。配置文件包含我使用 'i2cset' 模块的变量。如下所示: 这是我的配置文件,名为'try.ini'
[new]
a = ('i2cset', '-y', '0', '0x20', '0x14', '0x01')
我从我的主要代码中读取如下:
from ConfigParser import SafeConfigParser
parser=SafeConfigParser()
parser.read('try.ini')
def set21(tog=[0]):
tog[0]= not tog[0]
if tog[0]:
set0.config(text='p21_1')
A=parser.get('new', 'a')
subprocess.call(''.join(A), shell=True)
else:
set0.config(txt='p21_0')
但每次我执行主程序时都会收到一条错误消息:
/bin/sh: 1: 'i2cset ': not found.
我不知道为什么会这样。当我 运行 程序没有配置文件时,它执行得很好...... 有人可以帮忙吗..
亲切的问候, 纳米塔.
您的错误在于 .ini 文件的语法。
[new]
a = ('i2cset', '-y', '0', '0x20', '0x14', '0x01')
您希望变量 a
被读取为一个元组,而它实际上是一个包含 "('i2cset', '-y', '0', '0x20', '0x14', '0x01')"
.