Format string from CHOP values to textTOP

In my network I have CHOPs that output three different values. I want to take these values and create a text that is then placed in a textTOP. The idea is to create a version number.

What I have now is the values x, y and z that is created in CHOPs. I want to take these values to create a texttop that reads “Version: x.y.z”. I’m currently thinking of using DATs and python and format a string that way but to no success. Any ideas?

version = int(op('version')['k1']
seed = int(op('seed')['k2']
hotfix = int(op('hotfix')['k3']

verText = "VER" + version + "." + seed + "." + hotfix

op('text5').par.text = verText
1 Like

You could also dive into fStrings. A verry convinient way of formatting strings.
The core gist is that you start your string with an f and put python into { }
So for you it could be
op("text5").par.text = f"VER{version}.{seed}.{hotfix}"
Another cool thing is that you can also give the f-string formatting instructions for numbers using :x.xf. So your complete string could become this:
f"VER_{op('data')['ver'].eval():0.0f}.{op('data')['seed'].eval():0.0f}.{op('data')['hotfix'].eval():0.0f}"
Writing them into variables in script is advised though :slight_smile:
https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html#conversion-flags

2 Likes

Thank you so much, this was just the thing I was looking for!! Would’ve never figured it out on my own