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.1.tar.gz
.
File metadata
- Download URL: bracex-1.0.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 954fd07773db50ccdd42a9e95b9b078508e5e678b10b96249910945013840f52 |
|
MD5 | fd46a4e97529009b02d53b74d31fbb9f |
|
BLAKE2b-256 | 64a2eb55f1267df72f294220462c0a0d53a92fe1b1ba886fe02e5dbe366d18ec |
File details
Details for the file bracex-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: bracex-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 334ba782ac6c9666cf4ff57d49da9f133d2c004418dcf4f6e4b6898d8a501390 |
|
MD5 | 4c4c414478ae742a8b6dcf9629076354 |
|
BLAKE2b-256 | f6318657c59aecd4a9a39b74161caf7a63a875e085aa57890a0180ccc7291eac |