Python Forum
changing { and } in str.format()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing { and } in str.format()
#9
i did some string juggling to work around this. i configured the generator of the files to use some characters in place of '{' and'}' as if str.format() used them. that avoids different things with '{' or '}' from getting confused. then when i read in the file i swap characters around so '{' and'}' are present only where the format substitutions are (e.g. "{bucket}") and i call its .format() method with the settings. then i swap the characters back so the '{' and'}' are back where they are needed in the bash code being generated.

it turns out my original idea of using '[' and ']' would have similar problems because they are also used by the generated bash code. i found that '%' and '^' are not used, so those are the characters i am swapping with ... "{}" <-> "%^". so i read in "%bucket^", change it to "{bucket}" while the bash '{' and '}' get changed to '%' and '^', call .format(), then change '%' and '^' back to '{' and '}'. done. since this is being done with Python str type i could use some high up characters such as chr(65536) and chr(65537) which are extremely unlikely to be in the generated bash code.
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
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 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,752 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  changing format to Int Scott 3 2,511 Jun-19-2019, 06:33 AM
Last Post: ODIS
  Changing Number Format moby 4 5,107 May-24-2019, 11:04 PM
Last Post: snippsat
  Date Format Changing Program Not Working pyth0nus3r 2 4,806 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