Python Forum
changing { and } in str.format()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing { and } in str.format()
#4
I suggest to use mako templates which need a $ before the {}
>>> from mako.templates import Template
>>> s = "{et{ev}t}d${foo}}tu^tt${bar}tx}"
>>> Template(s).render(foo='hello', bar='world')
'{et{ev}t}dhello}tu^ttworldtx}'
>>> s = "{et{ev}t}d${foo}}tu^tt${bar**3}tx}"
>>> Template(s).render(foo='hello', bar=8)
'{et{ev}t}dhello}tu^tt512tx}'
Of course, there are still issues if the strings contain many % because this is also a part of mako's syntax.
Reply


Messages In This Thread
changing { and } in str.format() - by Skaperen - May-11-2019, 12:07 AM
RE: changing { and } in str.format() - by Larz60+ - May-11-2019, 02:50 PM
RE: changing { and } in str.format() - by Gribouillis - May-11-2019, 04:04 PM
RE: changing { and } in str.format() - by Skaperen - May-12-2019, 04:58 AM
RE: changing { and } in str.format() - by Skaperen - May-12-2019, 08:44 PM
RE: changing { and } in str.format() - by Skaperen - May-13-2019, 06:32 PM
RE: changing { and } in str.format() - by Skaperen - May-16-2019, 05:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,950 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  changing format to Int Scott 3 2,600 Jun-19-2019, 06:33 AM
Last Post: ODIS
  Changing Number Format moby 4 5,238 May-24-2019, 11:04 PM
Last Post: snippsat
  Date Format Changing Program Not Working pyth0nus3r 2 4,973 Jan-28-2017, 10:34 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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