I'm currently trying to slice a specific string into parts but alway getting out of index errors.
The string is:
columnData = "001.001.000.100.000.000.000"
myClassInstance = MyClass(
param1 = columnData[0:3],
param2 = columnData[4:3],
param3 = columnData[8:3],
param4 = 0,
param5 = columnData[12:3],
param6 = columnData[16:3],
param7 = columnData[20:3],
param8 = columnData[24:3]
)
Whenever it tries to set param8 I get the out of index error.
I then tried to put the slices into a file to see where the error is and tried:
f = open("TestmyTset.txt","w")
f.write(columnData)
f.write("\nparam1: ")
f.write(columnData[0:3])
f.write("\nparam2r: ")
f.write(columnData[4:3])
f.close();
but param2 was never printed into the file.
The output is:
001.001.000.100.000.000.000
param1: 001
param2:
So my question here is where my error is as I tried again and again and not finding it (in effect each of the slices shall be one of the . separated parts of the string).
As asked the expected outputs would be:
param1 = "001"
param2 = "001" (the 2nd 001 in the original string)
param3 = "000"
param4 = "0"
param5 = "100"
....