I have a config file using configParser
:
<br>
[ section one ]<br>
one = Y,Z,X <br><br>
[EG 2]<br>
ias = X,Y,Z<br>
My program works fine reading and processing these values.
However some of the sections are going to be quite large. I need a config file that will allow the values to be on a new line, like this:
[EG SECTION]<br>
EG=<br>
item 1 <br>
item 2 <br>
item 3<br>
etc...
In my code I have a simple function that takes a delimiter (or separator) of the values using string.split()
obviously now set to comma. I have tried the escape string of
which does not work.
Does anyone know if this is possible with python's config parser?
http://docs.python.org/library/configparser.html
# We need to extract data from the config
def getFromConfig(currentTeam, section, value, delimeter):
cp = ConfigParser.ConfigParser()
fileName = getFileName(currentTeam)
cp.read(fileName)
try:
returnedString = cp.get(section, value)
except: # The config file could be corrupted
print( "Error reading " + fileName + " configuration file." )
sys.exit(1) #Stop us from crashing later
if delimeter != "": # We may not need to split
returnedList = returnedString.split(delimeter)
return returnedList
I would use for this:
taskStrings = list(getFromConfig(teamName, "Y","Z",","))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…