Skip to main content

('IPython extension which allows assignment expressions (:=)', 'at the top level of an expression statement')

Project description

IPyWalrus

IPyWalrus is a simple IPython (Jupyter) extension which enables you to use the walrus operator (PEP 572 - Assignment Expressions) := for usual assignments in IPython or Jupyter.

This part of the 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.

is completely valid but my IPython sessions of Jupyter notebooks are full of cells like this one:

standard

and because it does not work in pure Python

error

I've prepared a small extension which makes it work:

ipywalrus

Usage

Install the extension from pip or download the ipywalrus.py and put it somewhere in PYTHONPATH:

# pip install ipywalrus

and load it in IPython or Jupyter

%load_ext ipywalrus

If you want to enable this extension permamently, create a default profile (if you don't have one already) ipython profile create and then add ipywalrus to the list of extensions in ~/.ipython/profile_default/ipython_config.py.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipywalrus-0.2.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

ipywalrus-0.2-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page