Using .len() in IF THEN statement in ArcMap field calculator

المشرف العام

Administrator
طاقم الإدارة
I have a string field with values of varying lengths (1-4). I need each value to have a length of 5 characters by adding zeros to the value until the length equals 5. For example:

123needs to be:

00123I am writing a Python function in ArcMap's Field Calculator but it is incorrect. This is my code:

def zeros(photoLen): if photoLen == 4: return "0" elif photoLen == 3: return "00" elif photoLen == 2: return "000" elif photoLen == 1: return "0000" else: return 0

And then I call the function like this:

zeros(!photoStr!)What do I need to change so this function will work?



أكثر...
 
أعلى