| Reference | Downloads | Github

Mixed variable+string content in a Text component

Hi all,

I am trying to display a mixture of fixed strings and variable contents inside a text component. I’ve done this in the past by enclosing the strings within triple pairs of inverted commas, prefixing string contents with $str(), and concatenating everything with plus signs (each + on its own line). Now, perhaps of changes to the most recent version of PsychoPy, this keeps giving a syntax error.

For instance, I tried variations of the following, set to change at “every repeat”:

"""the value"""
"""belongs to variable a"""

Any suggestions? Thanks!

OS (e.g. Win10): win8
PsychoPy version (e.g. 1.84.x): 3.1.0

It should be much simpler than all of that:

$'the value ' + str(a) + ' belongs to variable a'

or even simpler (using Python 3’s f-strings):

$f'the value {str(a)} belongs to variable a'

Ah - hadn’t tried it like that. Many thanks Michael!