Dmitry Telenkov 1 năm trước cách đây
mục cha
commit
f2b3791d82
3 tập tin đã thay đổi với 60 bổ sung4 xóa
  1. 15 0
      courses/python_indi/arb.py
  2. 41 0
      courses/python_indi/func.py
  3. 4 4
      jsonrpc/jsonrpc_test.py

+ 15 - 0
courses/python_indi/arb.py

@@ -0,0 +1,15 @@
+import jsonrpclib
+from threading import Thread
+
+class RPCClient(Thread):
+
+        def __init__(self):
+                self.client = jsonrpclib.Server('http://127.0.0.1:8082')
+
+        def test(self):
+                #print self.client.get_changes()
+                print self.client.get_info("DateTime")
+
+
+client = RPCClient()
+client.test()

+ 41 - 0
courses/python_indi/func.py

@@ -0,0 +1,41 @@
+from typing import Callable
+
+
+def calculate(x:float, y:float, operation:str='a') -> None:
+	def add():
+		print(x + y)
+	def sub():
+		print(x - y)
+	def div():
+		if y == 0:
+			print("На ноль делить нельзя!")
+		else:
+			print(x/y)
+	def mul():
+		print(x*y)
+
+	match operation:
+		case "a":
+			add()
+		case "s":
+			sub()
+		case "d":
+			div()
+		case "m":
+			mul()
+		case _:
+			print("Ошибка. Данной операции не существует")
+
+
+
+def get_math_func(operation: str) -> Callable[[int, int], int]:
+    def add(a: int, b: int) -> int:
+        return a + b
+
+    def subtract(a: int, b: int) -> int:
+        return a - b
+
+    if operation == "+":
+        return add
+    elif operation == "-":
+        return subtract

+ 4 - 4
jsonrpc/jsonrpc_test.py

@@ -52,11 +52,11 @@ class JSONRPCClient:
 		# 	print(jsonrpclib.history.response)
 		# 	time.sleep(3)
 
-		# self.client.get_changes()
-		self.client.get_opc_config()
+		self.client.get_changes()
+		# self.client.get_opc_config()
 
-		# print(jsonrpclib.history.request)
-		# print(jsonrpclib.history.response)
+		print(jsonrpclib.history.request)
+		print(jsonrpclib.history.response)
 		
 
 class ExampleService: