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:

images/standard.png

and because it does not work in pure Python

images/error.png

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

images/ipywalrus.png

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

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.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

ipywalrus-0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file ipywalrus-0.1.tar.gz.

File metadata

  • Download URL: ipywalrus-0.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6

File hashes

Hashes for ipywalrus-0.1.tar.gz
Algorithm Hash digest
SHA256 079db087d751da05c1819b5c146fc65a0b98697107a1538fb7d514184ed702ca
MD5 30399d2655b069c420b2396600dcc817
BLAKE2b-256 d45090b95579e5fcc3baaae80221431e6ab434d91eb6a175485d32d1bd8e76d5

See more details on using hashes here.

File details

Details for the file ipywalrus-0.1-py3-none-any.whl.

File metadata

  • Download URL: ipywalrus-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6

File hashes

Hashes for ipywalrus-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91e707dfe49898ad1fc8e84be9a2c04f480a37fee992fc05b60d25b5307f81ed
MD5 40d5f8c28816a8ea482d3132397acff3
BLAKE2b-256 3221ba1001c4e28b7c23c456f1170bcf4a2702a095cddae41cd042f6f8d5c430

See more details on using hashes here.

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