In one of my projects, I'm passing a serialized python instance as bytes type to the Javascript front end. At the javascript side When I console.log the this.model.get('MyInstance')
it returns MyInstance
as a data view object. Now I want to pass this instance back to the python kernel. My problem is that I am not able to get bytes type from the Data View object. A simple example would be something like this.
import pickle
def Hello():
print('hi')
a = pickle.dumps(Hello)
print(type(a))
print(a)
Output:
<class 'bytes'>
b'\x80\x04\x95\x16\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x05Hello\x94\x93\x94.'
What am I trying? :
Step-1
passing bytes to the javascript front end
b'\x80\x04\x95\x16\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x05Hello\x94\x93\x94.'
Step-2
It look likes when Javascript receives the bytes type it converts it to DataView
Step-3
In this case, I need to convert the Data view object back to bytes before passing it to the python kernel.
Step-4
Pass bytes back to python kernel.
I am using
trait lets to update the javascript backbone.js model.
MyInstace = Bytes(sync=True)
How to solve this problem please help.