stringFormat error Perspective

Hi,
I want to copy my labels into an email and I want to transfer integer into string, so I used stringFormat. However, I have this error:

Error running property change script on NumericEntryField.props.value: NameError: global name 'stringFormat' is not defined

with this OnChanged script:

if currentValue > self.getSibling("Limit").props.text:
		body = "Le " + self.getSibling("Nom").props.text + " de la " + stringFormat(" %d", (self.getSibling("Line").props.text)) + " a dépassé la limite maximum ajusté à " + stringFormat("%d", self.getSibling("Limit").props.text) +" mm avec une valeur de " + stringFormat("%d", currentValue)
		recipients = ["laurie.croteau@krugerproducts.ca"]
		system.net.sendEmail("mail.example.com:25", "mail.kruger.com", "Changement du diamètre de fin sur un Unwinder", body, 0, recipients)

Is it because I used .getSibling?

stringFormat is an expression function and you are writing Python/Jython code here.

You want to use Python’s string formatting library functions or syntax instead: 7.1. string — Common string operations — Python 2.7.2 documentation

I don’t understand the explanation in the link, but I found this and it work, thanks.

txt1 = "My name is {fname}, I'm {age}".format(fname = "John", age = 36)

Less obscure explanation of ‘new style’ formatting available in Python 2.7:
https://pyformat.info/

2 Likes