Some of my recent searching reveals embedding Python scripts in a LO document can done by manipulating the data in files within the zipped document. However effective this is, it is prone to error.
I have found much simpler way to do this. As the images I have used take considerable space, I have attached a document with all the necessary information. It is a very simple procedure.
As for the call in basic, change the basic script from:
oScript = oScriptProvider.getScript( "vnd.sun.star.script:get_os.py$get_OS?language=Python&location=user" )
To:
oScript = oScriptProvider.getScript( "vnd.sun.star.script:get_os.py$get_OS?language=Python&location=document" )
Note: The only thing changing is at the end of the line: ‘user’ to ‘document’.
Test the script.
Attachment: EmbedPythonScriptInDocument.odt
If this answers your question please click on the (upper left area of answer).