I am trying to read in a python file and split the lines into elements of an array. I am able to read and split the file content, however sometimes the leading white space for some of the elements gets removed.
Is there a way to split the file while making sure to retain all of the white spaces?
Here is my code to read in the file:
reader = new FileReader();
reader.onload = function (progressEvent)
var lines = file.split("\n");
Here is an example input:
def main():
print(1)
print(2)
def main2():
print(3)
#test
Here is the expected output:
0: "def main():"
1: " print(1)"
2: " print(2)"
3: "def main2():"
4: " print(3)"
5: " #test"
Here is the real output:
0: "def main():"
1: "print(1)"
2: "print(2)"
3: "def main2():"
4: "print(3)"
5: "#test"