I have hierarchy paths with varying numbers of levels (up to 4):
FACILITIES \ PARK
ROADS \ GRASS/TURF BLVD MAINTENANCE
ROADS \ SIDEWALKS \ REPLACEMENT
FACILITIES \ PARKING - MAIN ST
RECREATION \ BANDSHELL \ PROPERTY \ BUILDING-GENERAL
FACILITIES \ FIREHALL \ PLUMBING
FACILITIES
I want to parse the levels at the _\_
delimiter and insert the values into Maximo database columns:
- WOEQ1
- WOEQ2
- WOEQ3
- WOEQ4
(The length of those columns is only 10 right now. I will create proper custom columns with longer lengths later.)
What I've tried:
I've figured out how to parse the levels and insert the values into columns — IF (and that's a big IF) there are always 4 levels:
#Auto-script on WORKORDER
h = mbo.getString("HIERARCHYPATH")
mbo.setValue("WOEQ1", (h.split(' \\ '))[0][:10])
mbo.setValue("WOEQ2", (h.split(' \\ '))[1][:10])
mbo.setValue("WOEQ3", (h.split(' \\ '))[2][:10])
mbo.setValue("WOEQ4", (h.split(' \\ '))[3][:10])
But of course, I won't always have 4 levels. I can have any number of levels between 1-4.
How can I parse the backslash-delimited hierarchy path (with a varying number of levels)?
You can let "normal" splitting divide up your rows
Then you can iterate over your returned list, setting each value
If you need to always provide at least 4 (or N) members in your list, you could use
itertools.repeat
to fill in the remaining values