Dmitry Telenkov 1 年之前
父節點
當前提交
46d850bc8f
共有 4 個文件被更改,包括 119 次插入24 次删除
  1. 22 0
      courses/class.py
  2. 60 12
      courses/python_for_begginers/sort.py
  3. 26 12
      jsonrpc/jsonrpc_test.py
  4. 11 0
      jsonrpc/thread.py

+ 22 - 0
courses/class.py

@@ -0,0 +1,22 @@
+
+class Base():
+	
+	BASE_STRING = "Это базовый класс"
+
+	def __init__(self) -> None:
+		pass
+
+	def print_info(self):
+		print("Это метод базового класса: ", self.BASE_STRING)
+
+
+class UpBase(Base):
+
+	BASE_STRING = "Это класс наследник"
+
+	def __init__(self) -> None:
+		pass
+
+
+up_base = UpBase()
+up_base.print_info()

+ 60 - 12
courses/python_for_begginers/sort.py

@@ -59,16 +59,64 @@ subject_marks = [('English', 88), ('Science', 90), ('Maths', 88),
 
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-heroes = {
-    'Spider-Man': 80,
-    'Batman': 65,
-    'Superman': 85,
-    'Wonder Woman': 70,
-    'Flash': 70,
-    'Iron Man': 65,
-    'Thor': 90,
-    'Aquaman': 65,
-    'Captain America': 65,
-    'Hulk': 87,
-}
+models = [{'make': 'Nokia', 'model': 216, 'color': 'Black'},
+          {'make': 'Mi Max', 'model': 2, 'color': 'Gold'},
+          {'make': 'Samsung', 'model': 7, 'color': 'Blue'},
+          {'make': 'Apple', 'model': 10, 'color': 'Silver'},
+          {'make': 'Oppo', 'model': 9, 'color': 'Red'},
+          {'make': 'Huawei', 'model': 4, 'color': 'Grey'},
+          {'make': 'Honor', 'model': 3, 'color': 'Black'}]
+
+models = sorted(models, key=lambda x: x.get('color'))
+
+# for i in models:
+# 	print("Производитель: ", i.get('make'), ", модель: ", i.get('model'), ", цвет: ", i.get('color'), sep='')
+	
+
+
+# for i in sorted(models, key=lambda x : models.)
+
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# my_list = []
+
+# while True:
+# 	st = input()
+# 	if st == 'конец':
+# 		break
+# 	my_list.append(st.rpartition(':'))
+
+# for i in sorted(my_list, key=lambda x: -int(x[2])):
+# 	print(i[0])
+
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# n = int(input())
+# my_list = []
+# my_dict = {}
+
+# for i in range(n):
+# 	st = input()
+# 	if my_dict.get(st) == None:
+# 		my_dict.update({st: 1})
+# 	else:
+# 		my_dict.update({st: my_dict.get(st) + 1})
+
+# for key, value in my_dict.items():
+# 	my_list.append([key, value])
+
+# my_list = sorted(my_list, key=lambda x: x[1])
+
+# print(my_list[-1][0], ', ', my_list[-1][1], sep='')
+# print(my_list[0][0], ', ', my_list[0][1], sep='')
+
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+print(type(input().split()))
+
+# my_dict = {}
+# n = input()
+# for i in range(n):
+# 	st = input().split()
+
 

+ 26 - 12
jsonrpc/jsonrpc_test.py

@@ -15,14 +15,8 @@ class JSONRPCServer:
 		self.server.register_function(self.service.sumation, 'sum')
 		self.server.register_function(self.service.sumation, 'notify_sum')
 		self.server.register_function(self.service.sumation, 'namespace.sum')
-		# self.server.register_introspection_functions()
-		# self.JSONRPC_server.register_function(lambda x, y: x + y, 'add')
-		self.thread = threading.Thread(self.server.serve_forever)
-		self.thread.daemon = True
-		self.thread.stop = self.stop
+		self.thread = threading.Thread(target=self.server.serve_forever)
 		self.thread.start()
-		# self._wait_for_rpc_start() 
-		# time.sleeep(3)
 
 	def _wait_for_rpc_start(self):
 		rpc = jsonrpclib.Server("http://{0}:{1}".format(SERVER_ADDR[0], SERVER_ADDR[1]))
@@ -42,9 +36,28 @@ class JSONRPCServer:
 
 class JSONRPCClient:
 
-	def __init__(self) -> None:
-		self.client = jsonrpclib.Server("http://{0}:{1}".format(SERVER_ADDR[0], SERVER_ADDR[1]))
+	def __init__(self):
+
+		# self.client = jsonrpclib.Server("http://{0}:{1}".format(SERVER_ADDR[0], SERVER_ADDR[1]))
+		self.client = jsonrpclib.Server("http://{0}:{1}".format("192.168.31.226", 888))
+		# self.thread = threading.Thread(target=self.test)
+		# self.thread.start()
+
+	def test(self):
+		# while True:
+		# 	# print(self.client.get_device_info())
+		# 	# self.client.get_changes()
+		# 	self.client.get_changes()
+		# 	print(jsonrpclib.history.request)
+		# 	print(jsonrpclib.history.response)
+		# 	time.sleep(3)
 
+		# self.client.get_changes()
+		self.client.get_opc_config()
+
+		# print(jsonrpclib.history.request)
+		# print(jsonrpclib.history.response)
+		
 
 class ExampleService:
 	
@@ -66,11 +79,12 @@ class ExampleService:
 
 class ExampleAggregateService(ExampleService):
 	
-	def __init__(self) -> None:
+	def __init__(self):
 		self.sub_service = ExampleService()
 
 
 
-server = JSONRPCServer()		
+# server = JSONRPCServer()		
 client = JSONRPCClient()
-print(client.ping())
+client.test()
+# print(client.ping())

+ 11 - 0
jsonrpc/thread.py

@@ -0,0 +1,11 @@
+import threading
+import time
+
+def proc(n, s):
+	while True:
+		print('Поток №:', n)
+		time.sleep(s)
+
+
+threading.Thread(target=proc, args=[1, 1]).start()
+threading.Thread(target=proc, args=[2, 1.5]).start()