Js2Py
Js2Py copied to clipboard
JS function class to python
Hello @PiotrDabkowski I've translated this javascript file to python and got the XX object.
** JavaScript **
XX.WSVerifyCookieReq = function () {
this.lUid = 0;
this.sUA = "";
this.sCookie = "";
this.sGuid = "";
this.bAutoRegisterUid = 0
};
Can I declare a new WSVerifyCookieReq class which is equivalent to this?
** JavaScript **
verifyReq = new XX.WSVerifyCookieReq();
verifyReq.sUA = "new UA";
I tried like this but it's causing error.
verifyCookieReq = XX.WSVerifyCookieReq()
verifyCookieReq.sUA = "new UA"
Sorry, I didn't understand at first. I think you can implement it like this in python:
import js2py
context = js2py.EvalJs()
context.execute('''
var XX = [];
XX.WSVerifyCookieReq = function () {
this.lUid = 0;
this.sUA = "";
this.sCookie = "";
this.sGuid = "";
this.bAutoRegisterUid = 0
};
''')
verifyReq = context.XX.WSVerifyCookieReq._obj.create().to_python()
# Or verifyReq = context.eval("new XX.WSVerifyCookieReq()")
verifyReq.sUA = "new UA"