lightweight human-readable config?

Nick Vargish nav+posts at bandersnatch.org
Thu Oct 30 15:07:06 EST 2003


"John Roth" <newsgroups at jhrothjr.com> writes:

> for line in inFile.readlines():
>     key, value = line.split(":")
>     configdict[key] = value

for line in inFile.readlines():
    key, value = line.split(':', 1)  # only split once, values could
                                     # have ':' in them
    key = key.rstrip()     # remove trailing spaces from key
    value = value.lstrip() # remove leading spaces from value
    configdict[key] = value

You could reduce the last three lines to:

    configdict[key.rstrip()] = value.lstrip()

Nick

-- 
#  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this to a python
print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?')




More information about the Python-list mailing list