class MockDocument(object):

    def __init__(self):
        self.value = ''

def write(self, *args):
    self.value += ''.join(str(i) for i in args)


class Global(PyV8.JSClass):

    def __init__(self):
        self.document = MockDocument()
scope = Global()
ctx = PyV8.JSContext(scope)
ctx.enter()
ctx.eval(js)
print(scope.document.value)
Executing Javascript from Python