Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/csvoss/onelinerizer

Shamelessly convert any Python 2 script into a terrible single line of code
https://github.com/csvoss/onelinerizer

Last synced: 11 days ago
JSON representation

Shamelessly convert any Python 2 script into a terrible single line of code

Awesome Lists containing this project

README

        

Oneliner-izer
=========

[![Build Status](https://travis-ci.org/csvoss/onelinerizer.svg?branch=master)](https://travis-ci.org/csvoss/onelinerizer)

Convert any Python 2 script into a single line of code.

No newlines allowed. No semicolons, either. No silly file I/O tricks, or eval or exec. Just good, old-fashioned λ.

Play with a live demo at [onelinerizer.com](http://www.onelinerizer.com/)! Watch the [presentation at PyCon 2016](https://www.youtube.com/watch?v=DsUxuz_Rt8g), or peruse the [slide deck](https://speakerdeck.com/pycon2016/chelsea-voss-oneliner-izer-an-exercise-in-constrained-coding).

User Installation and Usage
---

Install via `pip` from PyPI:

```sh
$ pip install onelinerizer
```

Use either the command line function or the Python module:

```sh
$ echo "def f(x):\n print x\nf(4)" > sandbox.py
$ onelinerizer sandbox.py --debug
$ onelinerizer sandbox_ol.py
```

```python
from onelinerizer import onelinerize
onelinerize("def f(x):\n print x\nf(4)")
```

Examples
--------

**Before:**

```python
x = 3
y = 4
print (x < y < 5)
```

**After:**

```python
(lambda __builtin__: (lambda __print, __y, d: [[__print(d.x n:
print "Too big! Try again!"
elif user_input < n:
print "Too small! Try again!"
else:
print "You win!"
return True
guess_my_number(42)
```

**After:**

```python
(lambda __builtin__: (lambda __print, __y, d: [(lambda ___: None)(d.guess_my_number(42)) for d.guess_my_number in [(lambda n:[(__y(lambda __this: (lambda d: (lambda __after: [(lambda __after: (lambda ___: __after(d))(__print('Not a positive integer!')) if (d.len(d.user_input)==0 or (not d.user_input.isdigit())) else [(lambda __after: (lambda ___: __after(d))(__print('Too big! Try again!')) if d.user_input>d.n else (lambda __after: (lambda ___: __after(d))(__print('Too small! Try again!')) if d.user_input