Bash-style brace expansion for Python
|build-status-img| |PyPI|
Implements Brace Expansion as described in
bash(1) <http://man7.org/linux/man-pages/man1/bash.1.html#EXPANSION>
__,
with the following limitations:
A pattern containing unbalanced braces will raise an
UnbalancedBracesError
exception. In bash, unbalanced braces will
either be partly expanded or ignored.
A mixed-case character range like '{Z..a}'
or '{a..Z}'
will
not include the characters :literal:`[]^_`` between Z
and a
.
braceexpand
is tested with Python 2.7, and 3.6+
Install the braceexpand
package from pypi:
::
$ pip install braceexpand
The braceexpand
function returns an iterator over the expansions
generated from a pattern.
.. code:: python
from braceexpand import braceexpand
list(braceexpand('item{1..3}')) ['item1', 'item2', 'item3']
list(braceexpand('{a..c}')) ['a', 'b', 'c']
list(braceexpand('index.html{,.backup}')) ['index.html', 'index.html.backup']
list(braceexpand('python{2.{5..7},3.{2,3}}')) ['python2.5', 'python2.6', 'python2.7', 'python3.2', 'python3.3']
list(braceexpand('{07..10}')) ['07', '08', '09', '10']
list(braceexpand('{a..g..2}')) ['a', 'c', 'e', 'g']
list(braceexpand('{4..1}')) ['4', '3', '2', '1']
list(braceexpand('{2..-1}')) ['2', '1', '0', '-1']
list(braceexpand('{1{2,3}')) Traceback (most recent call last): ... UnbalancedBracesError: Unbalanced braces: '{1{2,3}'
list(braceexpand(r'{1{2,3}')) ['1{2', '3']
list(braceexpand(r'{1,2}', escape=False)) ['\1', '\2']
braceexpand is licensed under the MIT License. See the included file
LICENSE
for details.
.. |build-status-img| image:: https://travis-ci.org/trendels/braceexpand.svg :target: https://travis-ci.org/trendels/braceexpand .. |PyPI| image:: https://img.shields.io/pypi/v/braceexpand :target: https://pypi.python.org/pypi/braceexpand