I've got a table with a field named Maintenance Tasks. I would like to parse the values in this field into separate fields (Task1, Task2 etc.):
I can use:
None if !MaintenanceTasks! == None else !MaintenanceTasks!.split(',')[0]
and this will parse the first item correctly into Task1, it also accounts for any null values in MaintenanceTasks.
The problem I'm running into is, for example, OID 23 above, when there's just a single item in the MaintenanceTasks field (ReplaceHead).
Any help would be greatly appreciated. FWIW I'll be scripting in Python.
Just to add to my earlier reply - I thing the .count(",")+1 method might be a better idea, no?
I'm a list guy; gimme a list in python and I'll clean the plastic out of the oceans and get the furloughed fed works a pay check... All seriousness aside:
for i in range(len(someList)):
do you thing...
Personal preference is all....
I like Joshua's suggestion of the using a da.UpdateCursor too....
Joe, have you seen Ned Batchelder: Loop Like A Native ? I think you will find it worth the watch. Ned does a good job of showing how certain common patterns in other languages, e.g., for i in range(len(someList)), can be rewritten to be much more Pythonic.
I'll check it out.... thanx
enumerate...
try not to use …. range(len(something))
python linters will nail your code every time, and when you get used to it, it gives more and more possibilities.
good reading for the weekend Joe
cool... just tried it.....
Can you elaborate on this comment a bit, please? I'm pretty familiar with ArcPy, but this sounds more fundamental...
I won't steal any of Dan's thunder, but take a look here: 13. Enumerate — Python Tips 0.1 documentation . It's an alternative to what I suggested. The link Joshua provides is very good as well!
I had to watch it a couple times, maybe a few, to grasp all of the points he was raising. I watched it years ago, but it really did help me start to look at iterating/iterables/sequences in a different way than other languages. Python is awesome.
Skimmed it yesterday at work. Watched it again this morning with coffee... Gonna need a few more iterations of watching it and using the examples... (all puns intended.)