我是 DRY 的忠实拥护者,希望将我的CFG
文件拆分为公共部分和特定于环境的部分,并让环境部分从公共部分“继承”,如下所示:
[generic]
basedir = ~/computational-services/jobs
pattern = Job*
usage-jar = ../lib/usage-logging-client.jar
[dev-test]
age = 7
dirs = [
('%(basedir)s/rundir01', %(age)s, '%(pattern)s', 'cleanupRunDir01'),
('%(basedir)s/linuxNonimmediate', %(age)s, '%(pattern)s', 'cleanupLinuxNonimmediate01'),
]
[prod]
age = 14
dirs = [
('%(basedir)s/rundir01', %(age)s, '%(pattern)s', 'cleanupRunDir01'),
]
现在,我收到以下错误:
ConfigParser.InterpolationMissingOptionError: Bad value substitution:
section: [dev-test]
option : dirs
key : basedir
rawval : [
('%(basedir)s/rundir01', %(age)s, '%(pattern)s', 'cleanupRunDir01'),
('%(basedir)s/linuxNonimmediate', %(age)s, '%(pattern)s', 'cleanupLinuxNonimmediate01'),
]
如果我确实重复自己,并添加basedir
一切pattern
都[dev-test]
很好:
[dev-test]
age = 7
basedir = ~/computational-services/jobs
pattern = Job*
dirs = [
('%(basedir)s/rundir01', %(age)s, '%(pattern)s', 'cleanupRunDir01'),
('%(basedir)s/linuxNonimmediate', %(age)s, '%(pattern)s', 'cleanupLinuxNonimmediate01'),
]
有没有办法在另一个部分中使用一个键/值(甚至尝试过generic.basedir
and generic:basedir
)?
谢谢你。