我正在寻找一些类似于Java的Lombok的Python库。 我从2016年开始发现puffadder 0.1,但是现在我尝试使用pip进行安装,因此它不起作用。
链接:
Shell输出:
$ pip3 install puffadder
Collecting puffadder
Could not find a version that satisfies the requirement puffadder (from versions: )
No matching distribution found for puffadder
$ pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
$ pip3 install puffadder==0.1
Collecting puffadder==0.1
Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
No matching distribution found for puffadder==0.1
$ pip install puffadder==0.1
Collecting puffadder==0.1
Could not find a version that satisfies the requirement puffadder==0.1 (from versions: )
No matching distribution found for puffadder==0.1
$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
那么,它不再与现代版本的Python兼容吗? 为什么不再使用pip,不再使用pip或只是缺少pip集成(所以我可以从GitHub克隆它)。
此外,除了使用@property之外,有人知道其他受支持的替代方法吗?
答案 0 :(得分:3)
Python 3.7 添加了 dataclasses 这让我想起了 Java 中的 Lombok。它生成 _init_、_repr_ 等等。
@dataclass()
class Name:
first_name: str
last_name: str
yoni = Name("Yoni", "Alaluf")
yoni2 = Name("Jony", "Alaluf")
print(yoni) # Name(first_name='Yoni', last_name='Alaluf')
print(yoni2) # Name(first_name='Jony', last_name='Alaluf')
print(yoni == yoni2) # False