# Str.format() not working

**URL:** <https://forum.inductiveautomation.com/t/str-format-not-working/18058>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [May 16, 2018, 12:36pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058 "2018-05-16T12:36:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtaylor](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dtaylor](https://forum.inductiveautomation.com/u/dtaylor)\
**Post date:** [May 16, 2018, 12:36pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/1 "2018-05-16T12:36:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2018, 12:42pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/2 "2018-05-16T12:42:00Z")

</div>

Make sure you’re looking at Python 2.5 documentation.

[https://docs.python.org/release/2.5/lib/node40.html](https://docs.python.org/release/2.5/lib/node40.html)

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

---

<div class="post-metadata">

**Author:** ![dtaylor](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dtaylor](https://forum.inductiveautomation.com/u/dtaylor)\
**Post date:** [May 16, 2018, 12:48pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/3 "2018-05-16T12:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2018, 12:49pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/4 "2018-05-16T12:49:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [May 16, 2018, 1:57pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/5 "2018-05-16T13:57:52Z")

</div>

> [@Kevin.Herron](#):
>
> We upgraded to 2.7 in Ignition 8

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

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.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 16, 2018, 4:44pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/6 "2018-05-16T16:44:51Z")

</div>

Sanderd, we live in the future here. 🙂

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 16, 2018, 5:22pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/7 "2018-05-16T17:22:20Z")

</div>



---

<div class="post-metadata">

**Author:** ![mike.viens](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mike.viens/32/5182_2.png) [@mike.viens](https://forum.inductiveautomation.com/u/mike.viens)\
**Post date:** [May 16, 2018, 10:23pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/8 "2018-05-16T22:23:42Z")

</div>

Kevin / Kathy,

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

Such as: [Jep](https://github.com/ninia/jep)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2018, 10:38pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/9 "2018-05-16T22:38:16Z")

</div>

> [@mike.viens](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![mike.viens](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mike.viens/32/5182_2.png) [@mike.viens](https://forum.inductiveautomation.com/u/mike.viens)\
**Post date:** [May 16, 2018, 10:55pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/10 "2018-05-16T22:55:54Z")

</div>

Thanks for the fast response, Kevin. And not to keep beating the horse after he is dead, but there is also: [GraalVM](http://www.graalvm.org/)

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 16, 2018, 11:06pm UTC](https://forum.inductiveautomation.com/t/str-format-not-working/18058/11 "2018-05-16T23:06:39Z")

</div>

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.
