摘要: # Python 自定义运算符 #### 正向运算符 ``` + __add__(self, other) - __sub__(self, other) * __mul__(self, other) / __truediv__(self, other) // __floordiv__(self, o 阅读全文
posted @ 2023-08-16 17:37 软匠 阅读(101) 评论(0) 推荐(0)
摘要: # Python 类变量 除了定义对象属性外,Python 也可以定义类变量 #### 示例 ```python class ClassVariable: __object_count = 0 def __init__(self, name: str): self.name = name Class 阅读全文
posted @ 2023-08-15 19:01 软匠 阅读(47) 评论(0) 推荐(0)
摘要: # Python 依赖管理工具 poetry ## 安装 Linux, macOS, Windows (WSL) ``` curl -sSL https://install.python-poetry.org | python3 - ``` Windows (Powershell) ``` (Inv 阅读全文
posted @ 2023-08-13 16:14 软匠 阅读(707) 评论(0) 推荐(0)
摘要: # Python 访问控制 Java 中采用 public, protected, private 等修饰符来控制访问, Python 则采用命令约定来控制访问,一个下划线_开头表示保护方法,两个下划线__开头表示私有方法 Python 使用 @property 和 property setter 阅读全文
posted @ 2023-08-12 12:07 软匠 阅读(56) 评论(0) 推荐(0)
摘要: # Python 复杂数据排序 通过自定义函数作为 sort 的 key 来排序复杂数据 ``` def by_urgency(task): return task['urgency'] def test_sort_complicated(): tasks = [ {'title': 'Laundr 阅读全文
posted @ 2023-08-11 16:11 软匠 阅读(20) 评论(0) 推荐(0)
摘要: # python dict 和 object 的相互转换 dict.py 借助 __dict__, isinstance 来实现对象与字典之间的相互转换 ``` def as_dict(obj): if not hasattr(obj, "__dict__"): return obj result 阅读全文
posted @ 2023-08-10 17:35 软匠 阅读(240) 评论(0) 推荐(0)
摘要: # Java 9 新特性 ## 模块化系统 Java 9 引入模块化系统的一个原因是为了让 Java 可以运行在内存有限的场景 模块可以导出 Public API 隐藏内部实现,模块可以依赖其它模块 ``` module tech.ruanjiang.modules.car { requires t 阅读全文
posted @ 2023-08-09 15:02 软匠 阅读(24) 评论(0) 推荐(0)
摘要: # Java 11 新特性 Java 11 是 Java 8 之后的第一个长期支持版本 (long term suppoert LTS),Oracle 将在 2019年1月停止支持 Java 8. # Oracle VS Open JDK Java 10 是最后一个免许可商用版本,如果不需要 Ora 阅读全文
posted @ 2023-08-08 15:02 软匠 阅读(73) 评论(0) 推荐(0)
摘要: ## 自定义序列化和反序列化 可以实现 json.Marshaler 和 json.Unmarshaler 自定义json的序列化和反序列化 ``` type Tags []string func (t Tags) MarshalJSON() ([]byte, error) { return []b 阅读全文
posted @ 2023-08-07 18:32 软匠 阅读(99) 评论(0) 推荐(0)