javascript - How to automatically escape special characters in python but not the alphabetical ones? -


i'm writing python, , have unicode containing special characters, such double quotes , non english characters.

i want automatically escape special characters, when use re.escape escapes non english characters well. i'm not sure that's supposed happen.

anyway problematic because when python code writes javascript has unicode in it, javascript prints html element has these redundant slashes.

what doing wrong?

this resulting js code:

var mystring='\ע\נ\ב\ר' 

it should be

var mystring='ענבר' 

update: used json.dumps(...), adds additional quotes before , after. knows how remove that?

ended using this:

json.dumps(mystring, ensure_ascii=false)

works pretty far. added parameter leaves in unicode.

(but adds additional quotes before , after parts have unicode alphabetical characters, used mystring = mystring[1:-1]. that's little ugly, maybe there better solution...)


Comments