abbrev


Nameabbrev JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/rec/abbrev
Summary🐜 Expand abbreviations 🐜
upload_time2024-01-04 18:03:46
maintainer
docs_urlNone
authorTom Ritchford
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # 🐜 `abbrev`: Expand abbreviations 🐜

Expand a `Sequence` or `Mapping` of string abbreviations.

Handy when the user has a choice of commands with long names.

## Example 1: Use a list of choices

    import abbrev

    a = ['one', 'two', 'three']

    assert abbrev(a, 'one') == 'one'
    assert abbrev(a, 'o') == 'one'
    assert abbrev(a, 'tw') == 'two'

    abbrev(a, 'four')  # Raises a KeyError: no such key
    abbrev(a, 't')  # Raises a KeyError: ambiguous key ('two' or 'three'?)


## Example 2: Use a dictionary of choices

    import abbrev

    d = {'one': 100, 'two': 200, 'three': 300}

    assert abbrev(d, 'one') == 100
    assert abbrev(d, 'o') == 100
    assert abbrev(d, 'tw') == 200

## Example 3: Make an abbreviator to re-use

    import abbrev

    d = {'one': 100, 'two': 200, 'three': 300}

    abbreviator = abbrev(d)

    assert abbreviator('one') == my_abbrevs('o') == 100
    assert abbreviator('tw') == 200

## Example 4: Get all matches, when `multi=True`

    import abbrev

    a = ['one', 'two, 'three'}

    multi = abbrev(a, multi=True)  # Make an abbreviator

    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

## Example 5: Get only the first result, when `unique=False`

    import abbrev

    d = {'one': 100, 'two': 200, 'three': 300}

    assert abbrev(d, 't', unique=False) == (200, 300)


### [API Documentation](https://rec.github.io/abbrev#abbrev--api-documentation)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rec/abbrev",
    "name": "abbrev",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tom Ritchford",
    "author_email": "tom@swirly.com",
    "download_url": "https://files.pythonhosted.org/packages/7f/9a/20326277c558a83ef34803b7b4eb4ff1ab252d44dde4b6cc1786f0a240a1/abbrev-1.2.1.tar.gz",
    "platform": null,
    "description": "# \ud83d\udc1c `abbrev`: Expand abbreviations \ud83d\udc1c\n\nExpand a `Sequence` or `Mapping` of string abbreviations.\n\nHandy when the user has a choice of commands with long names.\n\n## Example 1: Use a list of choices\n\n    import abbrev\n\n    a = ['one', 'two', 'three']\n\n    assert abbrev(a, 'one') == 'one'\n    assert abbrev(a, 'o') == 'one'\n    assert abbrev(a, 'tw') == 'two'\n\n    abbrev(a, 'four')  # Raises a KeyError: no such key\n    abbrev(a, 't')  # Raises a KeyError: ambiguous key ('two' or 'three'?)\n\n\n## Example 2: Use a dictionary of choices\n\n    import abbrev\n\n    d = {'one': 100, 'two': 200, 'three': 300}\n\n    assert abbrev(d, 'one') == 100\n    assert abbrev(d, 'o') == 100\n    assert abbrev(d, 'tw') == 200\n\n## Example 3: Make an abbreviator to re-use\n\n    import abbrev\n\n    d = {'one': 100, 'two': 200, 'three': 300}\n\n    abbreviator = abbrev(d)\n\n    assert abbreviator('one') == my_abbrevs('o') == 100\n    assert abbreviator('tw') == 200\n\n## Example 4: Get all matches, when `multi=True`\n\n    import abbrev\n\n    a = ['one', 'two, 'three'}\n\n    multi = abbrev(a, multi=True)  # Make an abbreviator\n\n    assert multi('t') == abbrev(d, 't', multi=True) == ('two', three')\n    assert multi('o') == abbrev(d, 'o', multi=True) == ('one', )\n\n    multi('four')  # Still raises a key error\n\n## Example 5: Get only the first result, when `unique=False`\n\n    import abbrev\n\n    d = {'one': 100, 'two': 200, 'three': 300}\n\n    assert abbrev(d, 't', unique=False) == (200, 300)\n\n\n### [API Documentation](https://rec.github.io/abbrev#abbrev--api-documentation)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\ud83d\udc1c Expand abbreviations \ud83d\udc1c",
    "version": "1.2.1",
    "project_urls": {
        "Documentation": "https://rec.github.io/abbrev",
        "Homepage": "https://github.com/rec/abbrev",
        "Repository": "https://github.com/rec/abbrev"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56ab7081c4c1ad8fd06926e0d4bca279ecd5de48073d1de062f2fab89c17eb8b",
                "md5": "faa41b42be602b6157153275abfe84c6",
                "sha256": "ab1ed783c8b98897946d46aa31ce0fee7c18dd7a52b4b413ef5ef964fbfe2b30"
            },
            "downloads": -1,
            "filename": "abbrev-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "faa41b42be602b6157153275abfe84c6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3634,
            "upload_time": "2024-01-04T18:03:44",
            "upload_time_iso_8601": "2024-01-04T18:03:44.895470Z",
            "url": "https://files.pythonhosted.org/packages/56/ab/7081c4c1ad8fd06926e0d4bca279ecd5de48073d1de062f2fab89c17eb8b/abbrev-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f9a20326277c558a83ef34803b7b4eb4ff1ab252d44dde4b6cc1786f0a240a1",
                "md5": "e5aee96bea4dc291a455e37dd7508c85",
                "sha256": "5fa3f0ab570f470b62cf9da1e5454daf3f046bd12990718aaf3d4b2f28c42bf4"
            },
            "downloads": -1,
            "filename": "abbrev-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e5aee96bea4dc291a455e37dd7508c85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3068,
            "upload_time": "2024-01-04T18:03:46",
            "upload_time_iso_8601": "2024-01-04T18:03:46.135660Z",
            "url": "https://files.pythonhosted.org/packages/7f/9a/20326277c558a83ef34803b7b4eb4ff1ab252d44dde4b6cc1786f0a240a1/abbrev-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-04 18:03:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rec",
    "github_project": "abbrev",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "abbrev"
}
        
Elapsed time: 0.23251s