bjodah / pydollar

pydollar - use the dollar sign for assignment reflection in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pydollar

image

Build status

PyPI version

Python version

License

About pydollar

pydollar is a Python module which enables a non-native syntax for the dollar sign $ in Python code. It allows you to follow the DRY-principle (don't repeat yourself) more stricly when writing python code:

Take for example a file called mymodule.py:

from sympy import Symbol

def my_func():
    alpha, beta, gamma, delta, epsilon = symbs = list(map(Symbol, $))
    return symbs

we could then import from it by first intalling an import hook:

>>> import pydollar
>>> pydollar.install_import_hook()
>>> from mymodule import my_func
>>> from sympy import init_printing
>>> init_printing(pretty_print=True, use_unicode=True)
>>> sum([x**(i+1) for i, x in enumerate(my_func())])
     2    4    5    3
α + β  + δ  + ε  + γ 

Motivation

f-strings were a great additon to Python 3.6, the $ syntax follows it in spirit, it simply allows you to write succinct code.

If $ syntax (or more importantly, the functionality it provides) becomes official syntax there would be a real-world benefit to widely used codebases, e.g. SymPy:

https://github.com/sympy/sympy/blob/sympy-1.0/sympy/core/symbol.py#L587

Installation

Simplest way to install pydollar is to use pip:

$ python3 -m pip install --user pydollar

you can skip the --user flag if you have got root permissions.

Examples

See the test files under tests/.

License

The source code is Open Source and is released under the very permissive "simplified (2-clause) BSD license". See LICENSE for further details.

Contributing

Contributors are welcome to suggest improvements at https://github.com/bjodah/pydollar

Author

Björn I. Dahlgren, contact:
  • gmail address: bjodah

About

pydollar - use the dollar sign for assignment reflection in Python

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 99.2%Language:Shell 0.8%