AnsweredAssumed Answered

Python script if/for/while

Question asked by Cep86 on Jul 9, 2015
Latest reply on Jul 10, 2015 by dkwiens

*UPDATE*

For samples of the correct code, see posts below.

 

I'll start off by apologizing for not having any sort of sample of my code, but I am really just unsure on how to begin the code, so all I have is notes of what I need.

 

I have a feature class that has a number of fields that are duplicated for 5 different customers.  The fields that I need to focus on in this exercise are the Cust1Name, Cust1NodeID, Cust1HomeID, and 10 Cust1CircuitID fields.  I'm using "Cust1", "Cust2", etc only as examples in place of their actual names...just stating that to eliminate your efforts in trying to add the customer number in a potential for/while loop.  Essentially the fields look as they do below:

 

Cust1Name

Cust1NodeID

Cust1HomeID

Cust1CircuitID1

...

Cust1CirctuitID10

Cust2Name

Cust2NodeID

Cust2HomeID

Cust2CircuitID1

...

Cust2CircuitID10

etc...

 

My feature class has fields for all 5 customers, but not all 5 will be populated.  I've used the Cust#NodeID field as my reference for whether calculations will run or not because that field determines if they are needed or not.  Populated means run the calculation, while Null means do nothing.

 

if Cust1NodeID != None:
     return # insert calculation here
else:
     return None

 

I also need to get a users input to know the amount of circuit ID's needed.  The number varies from 1 to 10 circuit ID's.

 

numberIDs = arcpy.GetParameterAsText(0)

 

With this information I need the script to go through each Cust#NodeID field to check and see if it's null or not.  If it's null, keep moving...if it has data, calculate the amount of circuit ID fields needed based on the input.


Again, sorry for having nothing to start with.  I'm just confused on which route to take (for loop, while loop, if/if...), and I can't figure out any of them either way.  I'm just not sure how to add so many arguments together.

 

*EDIT*

I'll also note that the circuit ID calculation itself is just a concatenation of the given fields, as shown below:

Cust1CircuitID1 = (Cust1Name) - (Cust1NodeID) - (Cust1HomeID) - (01)

Cust1CircuitID2 = (Cust1Name) - (Cust1NodeID) - (Cust1HomeID) - (02)

etc...

Outcomes