I have properties file with multilines and some of the values on more than 1 line. Something like this:
first.key=\
Right,\
Side,\
Value
second.key=Second value
third.key=Third value
I want to take the value for each key. I am not able to preprocess the files, so I am not able to surround with triple quotes or anything else. So if I for examle want to put each key and value in line of the file in a list like:
for line in file:
split = line.split('=')
and then get key and value
key = split[0]
value = split[1]
print(key) -> first.key
print(value) -> \Right,\Side,\Value
for line in file:
while line.endswith('\\'):
line += next(file)
will give me TypeError: 'list' object is not an iterator
Keep in mind that each line of the properties file is item in a list. I am able to extract keys and values for each line, but I am struggling how to do it with multiline values. I should probably append next line to previous line if previous line.endswith('\'), but I am not able to figure it out. EDIT. ['multiline.key=First line of the value\', 'Second line of the value\', 'Third line of the value\', 'Fourth line of the value\', 'Fifth line of the value\', 'another.key=Some value', 'some.key= Another value'] I know how to deal with 'another.key=Some value', 'some.key=Another value'
What I cant figure out is how to extract as single value:
First line of the value\\', 'Second line of the value\\', 'Third
line of the value\\', 'Fourth line of the value\\', 'Fifth line of
the value\\'
for multiline.key
The file look like this:
multiline.key=First line of the value\
Second line of the value\
Third line of the value\
Fourth line of the value\
Fifth line of the value\
another.key=Some value
some.key=Another value
Expected result:
1st key=multiline.key
1st value=First line of the value\Second line of the value\Third
line of the value\Fourth line of the value\Fifth line of the value\
2nd key=another.key
2nd value=Some value
3rd key=some.key
3rd value=Another value