0

I have this class defined:

class Endpoint:
   recent_releases = "apps/{owner_name}/{app_name}/recent_releases"
   recent_latest = "apps/{owner_name}/{app_name}/releases/{release_id}"

and currently using format() to format it:

url = Endpoint.recent_releases.format(owner_name=owner_name, app_name=app_name)

Is it possible to format this using f-strings? I have tried this:

  class Endpoint:
      recent_releases = f"apps/{owner_name}/{app_name}/recent_releases"
      recent_latest = f"apps/{owner_name}/{app_name}/releases/{release_id}"

but I'd have create an __init__() function in the class.

FrancisV
  • 1,619
  • 5
  • 21
  • 36
  • 1
    No, you can't defer evaluation of `f`-strings, except by doing what you're already doing and using regular strings. – jonrsharpe Apr 06 '22 at 15:38
  • 1
    If your use case is the one I thinking on. Using computed properties would be a better choice. Since I imagine that you would like to get different owner_name and app_name for each Enpoint instance – Rubico Apr 06 '22 at 15:44
  • I should have looked further and found this after posting my question -- https://stackoverflow.com/questions/42497625/how-to-postpone-defer-the-evaluation-of-f-strings . I guess I'll be sticking to `.format()` for now. – FrancisV Apr 06 '22 at 15:58

0 Answers0