漂亮地将python对象打印到buche logger。

buche的Python项目详细描述


helper包,使用Buchelogger打印并与python对象交互。

这个包包括一个repl和一个调试器

需要Python>;=3.6

用法

必须首先安装Buche,可以从release安装,也可以通过npm(npm install -g buche)安装。这个包有助于与buche交互,但它不是应用程序本身。编写脚本后,请按如下方式使用:

python -m buche yourscript.py

或者,直接使用buche

buche python -u yourscript.py

显示

这里有一个你可以用布希做的例子。您可以使用buche python3 examples/demo.py运行此代码。

frombucheimportbuche,H# You don't have to set a template, but if you do, it must be the# very first command you emit, before any printing.# You can also give `src=<path-to-file>` instead of `content=...`buche.command_template(content=H.div['my-template'](address="/"))# Use this command to add styles, stylesheets, scripts, etc.buche.command_resource(content=H.style("""
    .my-template {
        background-color: #eee;
        padding: 5px;
        display: flex;
        flex-direction: column;
        align-items: start;
    }
    """))# Display simple HTMLbuche.html.h3('Welcome!')# Display objectsbuche(1234)buche([x*xforxinrange(100)])buche.dict(avocado="green",banana="yellow",cherry="red")# Open automatically creates an address for an elementdiv1=buche.open.div(style="border: 3px solid red")# You can also set an address explicitlybuche.html.div(address='/two',style="border: 3px solid blue")# Get a printer for the given addressdiv2=buche['/two']# These objects will go in the divsdiv1('One')div2('Two')div1('One again')# Handy tabs componentgrocery_list=buche.open.boxTabs()fruit=grocery_list.open.tabEntry(label='Fruits',active=True,)vegetable=grocery_list.open.tabEntry(label='Veggies',)fruit.html.div(H.s("Pineapple"))fruit.html.div("Raspberry")fruit.html.div("Grape")vegetable.html.div("Carrot")vegetable.html.div("Potato")vegetable.html.div("Yam")# Customize the representation of a classclassColor:def__init__(self,r,g,b):self.r=rself.g=gself.b=bdef__hrepr__(self,H,hrepr):sz=hrepr.config.swatch_sizeor20returnH.div(style=f'display:inline-block;width:{sz}px;height:{sz}px;margin:2px;'f'background-color:rgb({self.r},{self.g},{self.b});')# This will call __hrepr__buche(Color(255,0,0))# Configuration values can be anything and are propagated recursivelybuche(Color(0,0,255),swatch_size=50)# You can evaluate JavaScript on elementsbutton=buche.open.button("Tickle me")button.command_eval(expression="this.onclick = () => alert('Hihihihi!')")

回复

您可以很容易地启动交互式计算器:

# repl.pyfrombucheimportreplrepl.start()

运行buche python3 repl.py,您将得到一个空窗口和底部的一个输入框。您可以在输入框中计算python表达式并获得非常漂亮的输出,还可以单击对象的表示,以便将它们放入临时变量中。

注意:start是非阻塞的对于阻止版本,可以执行以下操作:

frombucheimportreplrepl.start(synchronous=True)repl.query()# Processes a single command, blocking

调试器

通过将环境变量PYTHONBREAKPOINT设置为buche.breakpoint,对内置breakpoint()的调用将使用buche的repl进行调试。您可以用与pdb基本相同的方式使用它,但是您可以得到漂亮的html打印。

PYTHONBREAKPOINT=buche.breakpoint buche python3 mycode.py

使用python -m buche运行脚本时会自动设置此变量。

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

推荐PyPI第三方库


热门话题
java testNG优先级和依赖性   java JPQL:以下WHERE子句使用继承时出现问题   java是否可以在JTable渲染器中进行查询?   java如何在javascript中向url添加变量并使用@PathVariable获取   在外部jframe中显示java控制台   java I无法连接到IBM MQ的QM错误2035 MQRC\u未授权   apache zookeeper如何解决Storm应用程序在本地集群中运行时出现的错误“java.net.ConnectException:连接被拒绝:connect”?   读取第一行的java文本文件具有键和第二行前进值   java在哪个线程池中affinityRun提交任务?如何配置线程数?   Java拆分字符串正则表达式:前导空格   如何在Java中读取Pop3服务器中的入站电子邮件   带/不带布局管理器的swing Java定位GUI组件   在Spring Webflux中使用域设置java多会话ID   http Java web将其内容刮除,但只刮除正文样式,然后不退出并永远运行   java图形绘制组件和循环故障