I'm using the advanced Python expression to build a label and am having trouble with the padding function in the format function as follows (rows is an arcpy SearchCursor output):
for row in rows:
if row.DETECTFLAG=='N':
texttoadd = ""
width1= 60-len(row.CHEMICALNM)
texttoadd = texttoadd + "{0}".format(row.CHEMICALNM) +"<BOL><ITA>{0:>{2}} {1}</ITA></BOL>".format(row.RRESTXT,row.LABQUALIFI,width1) + '\n'
myText3 = myText3 + texttoadd
elif row.FLAG == 'x' and row.DETECTFLAG=='Y':
texttoadd = ""
width2= 60-len(row.CHEMICALNM)
texttoadd = texttoadd + "{0}".format(row.CHEMICALNM)+ "<BOL><ITA><CLR red='255'>{0:>{2}} {1}</CLR></ITA></BOL>".format(row.RRESTXT,row.LABQUALIFI,width2) + '\n'
myText3 = myText3 + texttoadd
else:
texttoadd = ""
width3= 60-len(row.CHEMICALNM)
texttoadd = texttoadd + "{0}".format(row.CHEMICALNM)+"<BOL><ITA>{0:>{2}} {1}</ITA></BOL>".format(row.RRESTXT,row.LABQUALIFI,width3) + '\n'
myText3 = myText3 + texttoadd
the result of the myText3 variable is this:
I'm trying to use the format script to line up the column on the right side of the box.
Benzene 123245 J
Benzo(A)Pyrene 123 J
Silver 123456789
1,2-Dichlorobenzene ND U
I have tried to set a variable to the right justify (>{2} instead of an actual number) but it doesn't seem to work. My hunch is that the formatting tags are adding lengths to the string that need to be accounted for in the format function, but that's purely a shot in the dark right now.
Any tips on how to write the format function to pad the proper length?