自动或声明性地创建repr。

Represent的Python项目详细描述


PyPI VersionDocumentationTravisCoveragePython VersionMIT License

安装

$ pip install represent

自动生成

fromrepresentimportautorepr@autoreprclassRectangle:def__init__(self,name,color,width,height):self.name=nameself.color=colorself.width=widthself.height=heightrect=Rectangle('Timothy','red',15,4.5)print(rect)
Rectangle(name='Timothy', color='red', width=15, height=4.5)

声明生成

fromrepresentimportReprHelperMixinclassContrivedExample(ReprHelperMixin,object):def__init__(self,description,radians,shape,color,miles):self.description=descriptionself.degrees=radians*180/3.141592654self.shape=shapeself._color=colorself.km=1.60934*milesdef_repr_helper_(self,r):r.positional_from_attr('description')r.positional_with_value(self.degrees*3.141592654/180)r.keyword_from_attr('shape')r.keyword_from_attr('color','_color')r.keyword_with_value('miles',self.km/1.60934)ce=ContrivedExample('does something',0.345,'square','red',22)print(ce)fromIPython.lib.prettyimportpprintpprint(ce)
ContrivedExample('does something', 0.345, shape='square', color='red', miles=22.0)
ContrivedExample('does something',
                 0.345,
                 shape='square',
                 color='red',
                 miles=22.0)

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

推荐PyPI第三方库


热门话题
java Selenium运行ChromeDriver而不修改路径   java软件包sun。网www.protocol。https不可见   java AEM中的哪个类实现了javax。servlet。请求调度器接口?   在java/scala中读取zip或7z文件时的性能问题   java将一个文件写入另一个二进制文件   java在类本身中创建实例   Java中C#Action()委托的等价物?   java如何在任何类中使用@Context或类似工具获取ServletRequest?   重构(java)应该/如何重构此代码?   hibernate中的java TransientObject异常   gwt使用Java在CouchDB 2.0 fauxton中创建文档   xml错误Java Jersey:NotAuthorizedException:HTTP 401未经授权   java heroku错误:无法找到或加载主类   java从CAS 5.0检索已发布的属性。Spring Security中的x 3.2.5