Posts: 4,647
Threads: 1,494
Joined: Sep 2016
the .format() method does not always work with JSON strings. what do you guys use instead?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i have code that needs to put a string in where a {} is. it turns out the string where the {} is, is sometimes a string of some JSON. what .format seems to be doing is taking an earlier { and treating everything up a matching } (not sure which it used) as a string index. using .replace('{}',what_to_put_in) works.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
(Apr-02-2018, 07:47 PM)nilamo Wrote: I think you'd be better off parsing the json, and formatting whichever part needs to be formatted, instead of treating json as if it's a string.
that could be a lot of unpredictable parts when it's someone else's json.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
what i need is a .format that can be made to use something else instead of "{}" find where to substitute stuff. but nilamo is right. playing around with strings that could have anything in them can be dangerous.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.