Skip to main content

pydollar provides an installable import hook to support the dollar sign ($) as valid python syntax.

Project description

Build status PyPI version Python version https://zenodo.org/badge/8840/bjodah/pydollar.svg License airspeedvelocity coverage

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:

def my_func():
    hello, world = map(str.capitalize, $)
    print(hello, world)

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

>>> import pydollar
>>> pydollar.install_import_hook()
>>> from mymodule import my_func
>>> my_func()
('Hello', 'World')

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:

$ python -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

  • kth.se address: bda

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

pydollar-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file pydollar-0.1.1.tar.gz.

File metadata

  • Download URL: pydollar-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pydollar-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a9c763f397c7c594acbe3911ca097269ced1e7113fdaf3d87b033c4f64c06f21
MD5 e7ed05f45a56e5e87a2b3e70e0ac4cee
BLAKE2b-256 db148169158e82136b686bfcda63a813ac8af0db1abf820d4c2d61842b20b016

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page