Python f-string's in Jython

Is it possible to use f strings in Jython?


name = 'Keith'
print(f"My name is {name}")

would print ‘My name is Keith’

But I am assuming something java related is causing this to not run, is there a Jython equivalent?

Ignition 7.x is using Jython 2.5, Ignition 8.x is using Jython 2.7.

The feature you want was only introduced in Python 3.6, which hasn’t been released as Jython yet, but hopefully some day it will.

Awe bummer, I guess is the “best practice” route to just continue with the following?

name = 'Keith'
print "My name is " + name
name = 'Keith'
print "My name is %s" % name
1 Like

You do have regular sting replacements.

name = 'Keith'
print 'My name is %s' % name

and you should also have format strings (though I haven tried them, as I tend to not get into the habit python 2.7 since I also still program a lot on Ignition 7.x)

name = 'Keith'
print 'My name is {name}'.format(name=name)

You can do something similar in 2.5 with regular string replacements that I had forgotten about until I read @Sanderd17 reply:

sal = 'Hello,'
name = 'Keith'
print "%(sal)s my name is %(name)s" % {'sal':sal,'name':name}

This outputs

Hello, my name is Keith

You can find out more about the options for 2.5 string formatting here:


I think I like this one the best, I appreciate you guys clarifying this!
For reference on the “old” (2.5) and “new” (2.7) style formatting and pros/cons of each.