# -*- coding: iso-8859-15 -*-
#-Begin-----------------------------------------------------------------
import sys, win32com.server.register
import platform, struct
import tensorflow as tf
class PythonDemo:
#To create a new GUID use the commands:
#>>> import pythoncom
#>>> print(pythoncom.CreateGuid())
_reg_clsid_ = "{D1B0A23F-0B6E-46D6-8880-744DBFFB86CD}"
_reg_progid_ = "Python.Demo"
_reg_desc_ = "Python Demo COM Server"
_public_methods_ = ["HelloWorld", "HelloYou", "TensorFlow1", "TensorFlow2"]
#-Function HelloWorld-------------------------------------------------
def HelloWorld(self):
return "Hello World from Python " + platform.python_version() + \
" on " + platform.system() + " (" + platform.architecture()[0] + \
")"
#-Function HelloYou---------------------------------------------------
def HelloYou(self, name="Anybody"):
return "Hello " + str(name) + " from Python"
#-Function TensorFlow1------------------------------------------------
def TensorFlow1(self):
hello = tf.constant('Hello World from TensorFlow')
sess = tf.Session()
rc = sess.run(hello)
sess.close()
return str(rc)
#-Function TensorFlow2------------------------------------------------
def TensorFlow2(self):
a = tf.constant(10)
b = tf.constant(32)
sess = tf.Session()
rc = sess.run(a + b)
sess.close()
return str(rc)
#-Sub Main--------------------------------------------------------------
def main():
if sys.argv[1].lower() == "--register":
print("Registering COM server...")
if sys.argv[1].lower() == "--unregister":
print("Unregistering COM server...")
win32com.server.register.UseCommandLine(PythonDemo)
#-Main------------------------------------------------------------------
if __name__=="__main__":
main()
#-End-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
REPORT Z_PYTHON.
DATA:
lo_python TYPE OLE2_OBJECT,
lv_return TYPE STRING,
lo_list TYPE OLE2_OBJECT
.
CREATE OBJECT lo_python 'Python.Demo'.
CHECK sy-subrc = 0 AND lo_python-Handle > 0 AND lo_python-Type = 'OLE2'.
CALL METHOD OF lo_python 'HelloWorld' = lv_return.
WRITE: / lv_return.
CALL METHOD OF lo_python 'HelloYou' = lv_return
EXPORTING
#1 = 'Stefan'.
WRITE: / lv_return.
CALL METHOD OF lo_python 'TensorFlow1' = lv_return.
WRITE: / `Method TensorFlow1: ` && lv_return.
CALL METHOD OF lo_python 'TensorFlow2' = lv_return.
WRITE: / `Method TensorFlow2: ` && lv_return.
"-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |