Bash style brace expander.
Project description
Bracex
Bracex is a brace expanding library (à la Bash) for Python. Brace expanding is used to generate arbitrary strings.
> echo {{a,b},c}d
ad bd cd
Bracex adds this ability to Python:
>>> bracex.expand(r'file-{1,2,3}.txt')
['file-1.txt', 'file-2.txt', 'file-3.txt']
>>> bracex.expand(r'file-{1,2,3}.txt')
['file-1.txt', 'file-2.txt', 'file-3.txt']
>>> bracex.expand(r'-v{,,}')
['-v', '-v', '-v']
Nested braces:
>>> bracex.expand(r'file-{{a,b},c}d.txt')
['file-ad.txt', 'file-bd.txt', 'file-cd.txt']
Numerical sequences:
>>> bracex.expand(r'file{0..3}.txt')
['file0.txt', 'file1.txt', 'file2.txt', 'file3.txt']
>>> bracex.expand(r'file{0..6..2}.txt')
['file0.txt', 'file2.txt', 'file4.txt', 'file6.txt']
>>> bracex.expand(r'file{00..10..5}.jpg')
['file00.jpg', 'file05.jpg', 'file10.jpg']
Alphabetic sequences:
>>> bracex.expand(r'file{A..D}.txt')
['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt']
>>> bracex.expand(r'file{A..G..2}.txt')
['fileA.txt', 'fileC.txt', 'fileE.txt', 'fileG.txt']
Allows escaping:
>>> bracex.expand(r'file\{00..10..5}.jpg')
['file{00..10..5}.jpg']
>>> bracex.expand(r'file\{00..10..5}.jpg', keep_escapes=True)
['file\\{00..10..5}.jpg']
Bracex will not expand braces in the form of ${...}
:
>>> bracex.expand(r'file${a,b,c}.jpg')
['file${a,b,c}.jpg']
Install
> pip install bracex
API
expand
def expand(string, keep_escapes=False):
expand
accepts a string and returns a list of expanded strings. It will always return at least a single empty string [""]
. By default, escapes will be resolved and the backslashes reduced accordingly, but keep_escapes
will process the escapes without stripping them out.
iexpand
def iexpand(string, keep_escapes=False):
iexpand
is just like expand
except it returns a generator.
License
MIT License
Copyright (c) 2018 Isaac Muse
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bracex-1.0.tar.gz
.
File metadata
- Download URL: bracex-1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e71eb28073b2608dff5566e8306508bd78f7d632339d5b4fb2e113fc054c72 |
|
MD5 | 245b8dbbda3997203dd4a5b76dd7f5e3 |
|
BLAKE2b-256 | 55d188622c018522778fe21b7eff9cd4120a4b1d09dd765b8666f21d28935bcf |
File details
Details for the file bracex-1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: bracex-1.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f654662d30d92889ffd4501cfd4b1594306f0f0861b20767722a4cd8ad488b88 |
|
MD5 | 0d037d4ff582470b99952b7637ea29ff |
|
BLAKE2b-256 | 318567ab0111b3a86ea90f30661f1a115802d65388213ee91c30e76512ffd342 |