小编su7*_*u7k的帖子

python'with'语句,我应该使用contextlib.closing吗?

from contextlib import closing

def init_db():
    with closing(connect_db()) as db:
        with app.open_resource('schema.sql') as f:
            db.cursor().executescript(f.read())
        db.commit()
Run Code Online (Sandbox Code Playgroud)

这是来自烧瓶教程第3步(http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit).我对第4行感到好奇.

我必须导入并使用'contextlib.closing()'方法吗?

当我语句学习,很多文章说它会在下面的过程之后自动关闭文件.(与Last:thing.close()相同)

with open('filename','w') as f:
    f.write(someString);
Run Code Online (Sandbox Code Playgroud)

即使我不使用下面的contextlib.closing(),有什么区别?它来自2.7.6版本,谢谢.

def init_db():
    with connect_db() as db:
        with app.open_resource('schema.sql') as f:
            db.cursor().executescript(f.read())
        db.commit()
Run Code Online (Sandbox Code Playgroud)

python with-statement contextmanager

17
推荐指数
2
解决办法
7441
查看次数

plot.ly(dash_core_components)滑块颜色更改

昨天我第一次见到了plot.ly dash并创建了一些互动情节.我添加了dash_core_components.Slider()如下代码的对象.

dcc.Slider(
    id='month--slider',
    min=0,
    max=12,
    value=12,
    step=None,
    marks={'1': '1', '6': '6', '12': {'label': '12', 'style': {'color': 'red'}}}
)
Run Code Online (Sandbox Code Playgroud)

我已经阅读help(dcc.Slider)但我无法找到改变下方滑块天蓝色的方法.

在此输入图像描述

所以我的问题在这里......是否可以更改plot.ly dash的默认滑块的颜色(或样式)?先感谢您.

python plotly plotly-dash

4
推荐指数
2
解决办法
2334
查看次数