2023年10月14日

PostgreSQL: 转 PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署

本文转载之目的仅为备份之用,原文地址:https://blog.csdn.net/u010692693/article/details/121123843 目录: PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署(一) PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署(二) PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署(三) PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署(四) PostgreSQL高可用测试系列之Patroni + etcd + HAProxy + Keepalived 离线部署(五)…
2022年8月15日

Python: 练习 不定长参数

a = 'aa' b = 'bb' tuple_ = (a, b) dict_ = {'c': 'cc', 'd': 'dd'} def test(*args, **kwargs): print(args) for item in args: print(item) print(kwargs) for key, value in kwargs.items(): print(key, value) if __name__ == '__main__': test('vv', 'ww', x='xx', y='yy', *tuple_, **dict_) 结果: ('vv', 'ww', 'aa', 'bb') vv ww aa bb {'x': 'xx', 'y': 'yy', 'c': 'cc', 'd': 'dd'} x xx y yy c cc d dd 进程已结束,退出代码0…
2022年7月28日

Python: 练习 获取类中的自定义属性和方法

import inspect class A(object): a = 10 @classmethod def get_attribute(cls): print('1', vars(cls)) print('2', dir(cls)) print('3', cls.__dir__(cls)) print('4', cls.__dict__) print('5', locals()) print('6', globals()) print('*' * 20) attr_ = inspect.getmembers(cls, lambda a: not inspect.ismethod(a)) print('1', attr_) attr_ = filter(lambda a: not a[0].startswith('__'), attr_) print('2', attr_) attr_ = lis…
2022年6月22日

Python: 练习 简单http server 简单web框架

2022/02/simple_http_server_web_framework.zip import sys import threading import socket import os.path import json import struct import hashlib import re import framework from content_type import content_type class NetworkCommunicateRole(object): def role_choose(self): while True: role = input("请选择角色 Http服务(h)/服务端(s)/客户端(c):") if role == "h": return "http_server", elif role == "s": return "server", elif…
2022年6月21日

Python: 练习 函数装饰器实现单例

def decorator(cls): _instance = {} print(f"instance: {_instance}") def inner(): if cls not in _instance: _instance[cls] = cls() print(f"instance: {_instance}") return _instance[cls] return inner @decorator class ClassA(object): def __init__(self): self.a = 10 obj_1 = ClassA() obj_2 = ClassA() print(id(obj_1)) print(id(obj_2)) # ClassA = decorator(ClassA) # obj_A = ClassA() # print(obj_A.a)…
2022年6月19日

Python: 练习 PyMySQL

import pymysql connector = pymysql.connect(host="localhost", port=3306, user="root", password="", database="python", charset="utf8") cursor = connector.cursor() print(cursor.execute("show tables;")) print(cursor.fetchall()) print(cursor.execute("desc class;")) print(cursor.fetchall()) print(cursor.execute("select * from class;")) print(cursor.fetchall()) id_ = input("请输入ID:") paramete…
2022年6月16日

Python: 练习 深拷贝和浅拷贝

from copy import copy, deepcopy a_1 = [1, ["a", "b"]] a_2 = a_1.copy() print(id(a_1), id(a_1[0]), id(a_1[1])) print(id(a_2), id(a_2[0]), id(a_2[1])) print("*" * 20) # 浅拷贝 a_1 = [1, ["a", "b"]] a_2 = copy(a_1) print(id(a_1), id(a_1[0]), id(a_1[1])) print(id(a_2), id(a_2[0]), id(a_2[1])) print("*" * 20) # 深拷贝 a_1 = [1, ["a", "b"]] a_2 = deepcopy(a_1) print(id(a_1), id(a_1[0]), id(a_1[1])) print(id(a_2), id(a_2[0])…
2022年6月16日

Python: 练习 yield 创建生成器

generator_1 = (i for i in range(3)) print(generator_1) # print(*generator_1) print(next(generator_1)) print("*" * 20) for i in generator_1: print(i) print("*" * 20) def fibonacci(num): a = 0 b = 1 i = 0 while i < num: result = a a, b = b, a + b i += 1 yield result generator_2 = fibonacci(100) print(next(generator_2)) print("*" * 20) for i in generator_2: print(i)…
2022年6月16日

Python: 练习 with语句和上下文管理器 __enter__() 和 __exit__()方法 @contextmanager 装饰器

from contextlib import contextmanager class OpenFile(object): def __init__(self, file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True): self.file = file self.mode = mode def __enter__(self): print("OpenFileA上文方法") self.fd = open(self.file, self.mode) return self.fd def __exit__(self, exc_type, exc_val, exc_tb): print("OpenFileA下文方法") self.fd.close() @contextman…
2022年6月16日

Python: 练习 property属性 将方法当做属性进行使用

class PersonA(object): def __init__(self): self.__age = 20 @property def age(self): return self.__age @age.setter def age(self, new): self.__age = new class PersonB(object): def __init__(self): self.__age = 20 def get_age(self): return self.__age def set_age(self, new): self.__age = new age = property(get_age, set_age) person = PersonA() print("PersonA") print(person.age) person.age = 30 print(person.age)…