Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

string generator for bracket patterns

Project description

bracket_expansion

This library provides functions that allow you to define a string that contains brackets with numeric-ranges, and then expands that into a list of actual values.

There are two functions defined. The first function bracket_expansion will create a generator. You can then iterate through the generator.

The expansion supports multiple brackets. See examples.

If you want to create a concrete list from the generate, there is a function called expand which will do this as a convenience.

Installation

$ pip install bracket_expansion

Usage

Simple example:

from bracket_expansion import bracket_expansion

for if_name in bracket_expansion("Ethernet[1-48]"):
    print(if_name)

Would result in the output:

Ethernet1
Ethernet2
Ethernet3
...
Ethernet48

Multiple brackets:

You can define multiple brackets in the expression:

from bracket_expansion import bracket_expansion

for if_name in bracket_expansion("Ethernet[1-2]/[1-10]"):
    print(if_name)

Would result in the output:

Ethernet1/1
Ethernet1/2
...
Ethernet1/10
Ethernet2/1
Ethernet2/2
...
Ethernet2/10

For more details see the bracket_expansion docstring.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bracket-expansion, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size bracket_expansion-1.0.0-py3-none-any.whl (7.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size bracket_expansion-1.0.0.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page