I have String variables of the following format:
<?xml version="1.0" encoding="UTF-8"?>
<packages>
<package name="firstPackage" version="LATEST" params="xxx" force="false"/>
<package name="secondPackage" version="LATEST" params="xxx" force="false"/>
</packages>
My goal is to split the String + add to a list such that I end up with the following:
packages = ["<package name="firstPackage" version="LATEST" params="xxx" force="false"/>", "<package name="secondPackage" version="LATEST" params="xxx" force="false"/>"]
I am fairly new to Python but I believe the order of operations is:
- Split string by new line ("\n")
- For each line that is split this way, add to a list
To do this, I think I need a nested loop. The first loop to go through the initial multi-line Strings, but then another inside to break apart each line and store it as a separate list item. Below is some semi-pseudo code I have written:
variableList = [] # list containing Multi-line strings
packageList = [] # list to contain separated items
for item in variableList:
stringVariable = item
splitPackage = (stringVariable.split("\n"))
for package in splitPackage:
packageList.append(splitPackage)
Any help/advise would be appreciated.
splitlines()function.