Python Forum
dynamic f-string example
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamic f-string example
#5
in your example, and an apparent requirement for format(), is the need to know which variables will be used. what if the scope of variables that could be used is very large, such as several dozen possible variables, even though the actual strings might only use a few. but the code does not get to know a few.

i see you changed the string literals making up the list to f-strings (literals). i had them as plain old strings for a reason. they served as an example of how a plain old string would be used. what if my example had shown the 3 strings being read from 3 different files? then how would you code that?

the point is: you have a string (type str) with the format in it, just as you would have between quotes in an f-string literal. but this string did not come from an f-string literal. it doesn't matter where it came from. it is type str and contains a format that has not yet been processed. now, it needs to be processed in exactly the same way the source between quotes is processed in an f-string literal. of course, this is a rare need. but, the chance of it is not zero.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
dynamic f-string example - by Skaperen - Feb-16-2020, 03:53 AM
RE: dynamic f-string example - by DeaD_EyE - Feb-16-2020, 12:09 PM
RE: dynamic f-string example - by Skaperen - Feb-17-2020, 12:09 AM
RE: dynamic f-string example - by DeaD_EyE - Feb-17-2020, 07:08 AM
RE: dynamic f-string example - by Skaperen - Feb-18-2020, 12:51 AM
RE: dynamic f-string example - by DeaD_EyE - Feb-18-2020, 09:31 AM
RE: dynamic f-string example - by Skaperen - Feb-18-2020, 06:49 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020