0
Hello, this is my first question here, I have a string and in it I need for a random value, however, when making it formatted, other keys inside become a placeholder, but that’s not what I want.It’s this code: The string is about-if from a java script Function, and in it there are keys, there are as I "disregard these keys" in the format string?
import random
number = random.randint(280, 320)
func = f"""
function saveToLocalStorage(e) {
var t = localStorage.getItem("readData2") || "[]",
t = JSON.parse(t),
n = {
slug: e["viewed_book[book_slug]"],
percentage: e["viewed_book[percentage]"],
initial_percentage: e.initial_percentage,
final_percentage: e.final_percentage,
resume_element_id: e.resume_element_id,
resume_doc_id: e.resume_doc_id,
time_spent: {},
viewed_book_id: gon.viewed_book,
words_per_minute: e.words_per_minute,
token: e.token
},
r = t.concat(n);
localStorage.setItem("readData2", JSON.stringify(r))
}""".
print(func)
Just escape the keys by replacing the
{
for{{
and}
for}}
, but in your case I think it would be best to simply remove thef
at the beginning of the string, since you are not using even interpolation.– Andre
Man, thank you so much! The use of two keys served me!
– Thunder - 41