-1

I'm looking for a wiki site for interchangeable Python variables. I don't know what those are called so i can't look them up.

An example:

template = ['{sti}_Data', '{sti}_OtherData', '{sti}_MaxData']

si = name

What is this method called ?

Amundi
  • 103
  • 1
  • 2
    I think you have to put some work into your question, because it is highly unclear what you mean. What is your example code supposed to achieve, because it certainly cannot be executed as it stands – FlyingTeller Sep 07 '18 at 13:00
  • You may be referring to the concept popularly known as "[variable variables](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables)". They are generally considered an antipattern and should be avoided whenever possible. – Kevin Sep 07 '18 at 13:00

1 Answers1

0

I think this is basically Python string formatting?

to use your example,

template = ['{}_Data', '{}_OtherData', '{}_MaxData']
si = 'Sauron'
results = [x.format(si) for x in template]
print(results)
# ['Sauron_Data', 'Sauron_OtherData', 'Sauron_MaxData']

There's more here, but I think you'll find much more if you just google Python string fomatting.

https://pyformat.info/

Liudvikas Akelis
  • 1,164
  • 8
  • 15