Str.format() not working

In a script (not Expression) I’m trying to format a two digit int into a zero padded string. i.e.: 22->‘22’ and 4->‘04’

I tried the following from Python documentation:

'{:02d}'.format(currIndex)

I get the following error:

AttributeError: 'str' object has no attribute 'format'

Should this work? If not, why? Also, if not what should I use?

Make sure you’re looking at Python 2.5 documentation.

https://docs.python.org/release/2.5/lib/node40.html

The format method you’re trying to use was introduced in 2.6.

Kevin,

Thanks, that did it.
‘%2d’ % (currIndex,)

Are there any plans to move to a more recent version of Python? Is the old format in danger of being deprecated?

Doug

We upgraded to 2.7 in Ignition 8, which is the latest version supported by the Jython project.

2 Likes

Strange usage of the past tense here (given that Ignition 8 isn't released yet) :wink:

But anyway great to hear you're moving to python 2.7. There are a lot more 2.7-compatible tools, libraries and tutorials out in the wild. Mainly because it's possible to write python code that's compatible with 2.7 and python 3.3+.

@dtaylor, AFAIK one of the reasons that Ignition still uses 2.5 is to support Java 6. Jython 2.7 dropped Java 6 support, so Ignition needs a "big release" to also drop Java 6 support.

1 Like

Sanderd, we live in the future here. :slight_smile:

Kevin / Kathy,

Given that Jython is so old, have you given any consideration to moving to something else?

Such as: Jep

Jep seems neat, but being JNI-based it means a crash bug takes down your client, designer, or gateway entirely.

1 Like

Thanks for the fast response, Kevin. And not to keep beating the horse after he is dead, but there is also: GraalVM

Certainly with JNI, that would not be a practical solution.

Yeah, Graal is new and certainly interesting. Too soon to figure out how it might be used. Haven’t even tried running Ignition on it yet.