('IPython扩展,允许在表达式语句的最高级使用赋值表达式 (:=)', '在表达式语句的最高级')
项目描述
IPyWalrus
IPyWalrus是一个简单的IPython(Jupyter)扩展,允许您在IPython或Jupyter中使用walrus运算符(PEP 572 - 赋值表达式):=
进行常规赋值。
PEP的这一部分
There are a few places where assignment expressions are not allowed, in order to avoid ambiguities or user confusion:
Unparenthesized assignment expressions are prohibited at the top level of an expression statement. Example:
y := f(x) # INVALID
(y := f(x)) # Valid, though not recommended
This rule is included to simplify the choice for the user between an assignment statement and an assignment expression -- there is no syntactic position where both are valid.
完全有效,但我的IPython会话中的Jupyter笔记本充满了这样的单元格
并且因为它在纯Python中不起作用
我准备了一个小的扩展,使其工作
用法
从pip安装扩展或下载ipywalrus.py并将其放入PYTHONPATH
中的某个位置
# pip install ipywalrus
并在IPython或Jupyter中加载它
%load_ext ipywalrus
如果您想永久启用此扩展,创建默认配置文件(如果您还没有的话)ipython profile create
然后向~/.ipython/profile_default/ipython_config.py
中的扩展列表中添加ipywalrus。
许可证
MIT
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
ipywalrus-0.2.tar.gz (2.8 kB 查看哈希值)
构建分布
ipywalrus-0.2-py3-none-any.whl (3.5 kB 查看哈希值)