提供构造函数参数的混合。

ctorrepr的Python项目详细描述


ctorrepr

https://img.shields.io/pypi/v/ctorrepr.svghttps://img.shields.io/travis/astralblue/ctorrepr.svgDocumentation StatusUpdates

提供构造函数参数的混合。

使用量

要使用,只需从~ctorrepr.ctorrepr继承,然后实现 < cTrRePr.cTrReR.Pr.ExpRePrgARGSH()/cTIT>以匹配您的现有 __init__()方法:

>>> from ctorrepr import CtorRepr
>>> class X(CtorRepr):
...     def __init__(self, x1='x1', x2='x2', *poargs, **kwargs):
...         super().__init__(*poargs, **kwargs)
...         self.x1 = x1
...         self.x2 = x2
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         poargs[:0] = self.x1, self.x2
>>> class Y(CtorRepr):
...     def __init__(self, *y, **kwargs):
...         super().__init__(**kwargs)
...         self.y = y          # completely consumes positional args
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         poargs[:0] = self.y
>>> class Z(CtorRepr):
...     def __init__(self, *poargs, zk='zk', **kwargs):
...         super().__init__(*poargs, **kwargs)
...         self.zk = zk
...     def _collect_repr_args(self, poargs, kwargs):
...         super()._collect_repr_args(poargs, kwargs)
...         kwargs.update(zk=self.zk)
>>> class W(X, Y, Z):
...     def __str__(self):
...         return repr(self)
>>> print(' '.join(t.__name__ for t in W.mro()))
W X Y Z CtorRepr object
>>> print(W())
W('x1', 'x2', zk='zk')
>>> print(W(24))
W(24, 'x2', zk='zk')
>>> w = W(24, 25, 'y1', 'y2')
>>> w.y
('y1', 'y2')
>>> print(w)
W(24, 25, 'y1', 'y2', zk='zk')
>>> print(W(zk=100))
W('x1', 'x2', zk=100)

学分

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

0.1.0(2017-07-31)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java实现的一个简单算法(计算概率)   更改应用程序背景动画的java首选项   java捕获图像并通过socket发送   基于双精度数组的对象的java排序Arraylist?   java似乎无法获得前面数字的正确总和   java卡住了Tomcat线程。日食乐观锁定   java是一个异步的Throwable类的printStackTrace()   java随机错误(可能是)Android支持库   java我应该在代码中自动创建DB表,还是在安装过程中使用preinit?   在被调用的方法/函数Java/Android中处理异常?   arraylist Java发送电子邮件非法分号?   while循环中的Java数组   java Arquillian和TransactionAttribute类型。需要新的   java“未找到合适的驱动程序”获取此错误   java高性能地将子类转换为真正的超类   java如何从另一个活动访问变量   安卓 Java Kotlin泛型将类getter作为参数传递到函数中   尝试访问数组的某个位置时需要java“]”