# -*- coding:UTF-8 -*-import execjsclass jsReg(): def __init__(self): self.ctx = execjs.compile(""" function reg(text) { return text } """) def get_reg_text(self, text): print(text) a = '''adasd \nadad''' return self.ctx.call('reg', str(text))1.給js傳a,一切正常2.給js傳txt read出來,decode('utf-8')的數(shù)據(jù)text,就報錯'ascii' codec can't decode byte 0xe2 in position 302: ordinal not in range(128)。目前我可以直接傳b'...'字節(jié)數(shù)據(jù)給js,只是js那邊需要轉(zhuǎn)一下。我也想直接傳字符數(shù)據(jù)'...'給js,但是報錯編碼問題。有一點不明的是,a 和 text的數(shù)據(jù)有什么區(qū)別?為什么a可以傳給js,text解碼讀出來的數(shù)據(jù)傳給js時,報編碼錯誤?感謝劍心無痕的耐心解答。目前得驗證在VS Code下,js傳str到python會有編碼問題,雖然沒有完全解決。但和我最開始的目標(biāo)沒有關(guān)系了。不過也想知道是VS Code的什么bug?先搞完自己的小玩具先....腳本command沒問題,就是這段代碼不能在VS Code里調(diào)試了 - -感謝劍心無痕的耐心解答。!
python execjs傳參給js遇到的問題
胡說叔叔
2019-03-07 21:54:49