从jupyter-notebook学python

1 篇文章 0 订阅
1 篇文章 0 订阅

从notebook学python

  • 由于项目经常用到jupyter-notebook,所以经常会去看jupyter-notebook的源码。由于python本身的可读性比较强,再加上jupyter-notebook源码的注释写的非常完备,所以还是比较容易看懂的。

  • 通过阅读jupyter-notebook的源码,学习到了很多python的写法和逻辑,在这里分享给大家。

  • 未完待续……
# 在类中调用init方法
class VolumeShareSlippage(SlippageModel):
    """
    Model slippage as a function of the volume of contracts traded.
    """
    def __init__(self, volume_limit=DEFAULT_EQUITY_VOLUME_SLIPPAGE_BAR_LIMIT,
                 price_impact=0.1):

        super(VolumeShareSlippage, self).__init__()

        self.volume_limit = volume_limit
        self.price_impact = price_impact

# 匿名函数lambda用法,获取函数返回值作为传入值
if not future.done():
    self.log.debug("Waiting for pending kernel_info request")
    future.add_done_callback(lambda f: self._finish_kernel_info(f.result()))

# del用法,删除列表中的特定元素
now = IOLoop.current().time()
while len(self._iopub_window_byte_queue) > 0:
queued = self._iopub_window_byte_queue[0]
if (now >= queued[0]):
    self._iopub_window_byte_count -= queued[1]
    self._iopub_window_msg_count -= 1
    del self._iopub_window_byte_queue[0]
else:
    # This part of the queue hasn't be reached yet, so we can
    # abort the loop.
    break

# not in 用法
if channel == 'iopub' and msg_type not in {'status', 'comm_open', 'execute_input'}:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值