abbrev-1.0.1
توضیحات
A dictionary that allows abbreviations
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | abbrev-1.0.1 |
| نام | abbrev |
| نسخه کتابخانه | 1.0.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Tom Ritchford |
| ایمیل نویسنده | tom@swirly.com |
| آدرس صفحه اصلی | https://github.com/rec/abbrev |
| آدرس اینترنتی | https://pypi.org/project/abbrev/ |
| مجوز | MIT |
🐜 abbrev: look up abbreviations in a dictionary 🐜
Handy when the user has a choice of commands with long names.
EXAMPLE
=========
.. code-block:: python
import abbrev
d = {'one': 1, 'two': 2, 'three': 3}
assert abbrev(d, 'one') == 1
assert abbrev(d, 'o') == 1
assert abbrev(d, 'tw') == 2
abbrev(d, 'four') # Raises a KeyError: no such key
abbrev(d, 't') # Raises a KeyError: ambiguous
# You can "curry" a specific dictionary, and save it to call:
curry = abbrev(d)
assert curry('one') == 1
assert curry('tw') == 2
# In multi mode, you get all the results:
multi = abbrev(d, multi=True)
assert multi('t') == abbrev(d, 't', multi=True) == ('two', 'three')
assert multi('o') == abbrev(d, 'o', multi=True) == ('one', )
multi('four') # Still raises a key error
# Turn off unique, and you get the first result:
assert abbrev(d, 't', unique=False) == ('two',)
API
---
``abbrev()``
~~~~~~~~~~~~
.. code-block:: python
abbrev(
abbrevs,
key=abbrev.NONE,
default=abbrev.NONE,
multi=False,
unique=True,
)
(`abbrev.py, 47-106 <https://github.com/rec/abbrev/blob/master/abbrev.py#L47-L106>`_)
Look up abbreviations in a dictionary. Handy when the user
has a choice of commands with long names.
ARGUMENTS
abbrevs:
A dictionary with string keys or a sequence of strings
key:
An abbreviated key to look up in ``abbrevs``,
If ``key`` is omitted, ``abbrev`` returns a callable that looks up
abbreviations in ``abbrevs``
default:
if ``key`` is not found in the dictionary, ``default`` is returned, if it's
set. Otherwise, missing keys throw a KeyError
multi:
If True, a tuple of matching keys is returned on a match
If False, the default, only a single matching value is returned
unique:
If True, the default, ``abbrev`` raises a KeyError if more than one key
matches. If False, ``abbrev`` returns the first match.
``unique`` is ignored if ``multi`` is set
(automatically generated by `doks <https://github.com/rec/doks/>`_ on 2021-06-12T16:46:04.893076)
نحوه نصب
نصب پکیج whl abbrev-1.0.1:
pip install abbrev-1.0.1.whl
نصب پکیج tar.gz abbrev-1.0.1:
pip install abbrev-1.0.1.tar.gz