https://github.com/bjodah/pydollar
pydollar - use the dollar sign for assignment reflection in Python
https://github.com/bjodah/pydollar
domain-specific-language importer python-3 syntax-sugar
Last synced: about 1 year ago
JSON representation
pydollar - use the dollar sign for assignment reflection in Python
- Host: GitHub
- URL: https://github.com/bjodah/pydollar
- Owner: bjodah
- License: bsd-2-clause
- Created: 2017-03-14T00:42:22.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-06T23:14:00.000Z (over 6 years ago)
- Last Synced: 2025-02-28T08:38:47.258Z (over 1 year ago)
- Topics: domain-specific-language, importer, python-3, syntax-sugar
- Language: Python
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
pydollar
========
.. image:: https://travis-ci.org/bjodah/pydollar.png?branch=master
:target: https://travis-ci.org/bjodah/pydollar
.. image:: http://hera.physchem.kth.se:9090/api/badges/bjodah/pydollar/status.svg
:target: http://hera.physchem.kth.se:9090/bjodah/pydollar
:alt: Build status
.. image:: https://img.shields.io/pypi/v/pydollar.svg
:target: https://pypi.python.org/pypi/pydollar
:alt: PyPI version
.. image:: https://img.shields.io/badge/python-3.5,3.6-blue.svg
:target: https://www.python.org/
:alt: Python version
.. image:: https://img.shields.io/pypi/l/pydollar.svg
:target: https://github.com/bjodah/pydollar/blob/master/LICENSE
:alt: License
.. contents::
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``:
.. code:: python
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:
.. code:: python
>>> 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