Skip to main content

Implementing C-style for loops in Python for fun.

Project description

cursed-for

Implementing C-style for loops in Python.

This was implemented because of a cursed idea I had one night, which I put on twitter:

I wrote a blog on the approaches I went through to implement this.

The rough iterations that happened during the development are documented in the approach folder. It contains both the AST manipulation method, and the "truly cursed" method.

Installation

pip install cursed-for

The "old way" usage

Note that this only really works in a REPL. To start it, run cursedfor.py in the terminal. It's a single file, you can get it by just downloading the one file if you want to.

>>> from cursed_for import _for, var
>>> with _for(i := var(0), i < 10, i += 2):
...     print(i)
0
2
4
6
8

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cursed_for-0.1.0-py3-none-any.whl (4.8 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