semvec/pypi-packages huggingface dataset:
swap-exceptions 1.0.2
Python utility decorator and context manager for swapping exceptions
License: MIT
Requires Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
Keywords: swap,exceptions,switch,replace,utility

# swap-exceptions

[![PyPI](https://img.shields.io/pypi/v/swap-exceptions)](https://pypi.org/project/swap-exceptions/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/swap-exceptions)](https://pypi.org/project/swap-exceptions/)
[![PyPI License](https://img.shields.io/pypi/l/swap-exceptions)](https://pypi.org/project/swap-exceptions/)
[![Code Style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black/)

Python utility decorator and context manager for swapping exceptions.

### Basic Usage

As a decorator:
```python
from swap_exceptions import swap_exceptions

@swap_exceptions({KeyError: ValueError("Incorrect value")})
def get_value(key: str):
    d = {'a': 1, 'b': 2}
    return d[key]

get_value('c')  # ValueError: Incorrect value
```

Or as a context manager:
```python
from swap_exceptions import swap_exceptions

def get_value(key: str):
    d = {'a': 1, 'b': 2}
    with swap_exceptions({KeyError: ValueError("Incorrect value")}):
        return d[key]

get_value('c')  # ValueError: Incorrect value
```

### Advanced Usage

Mapping key can also be a tuple:
```python
from swap_exceptions import swap_exceptions

@swap_exceptions({(KeyError, TypeError): ValueError("Incorrect value")})
def get_value(key: str):
    d = {'a': 1, 'b': 2, 'c': 'not a number'}
    return d[key] + 10

get_value('c')  # ValueError: Incorrect value
```

Mapping value can also be a factory that generates the exception:
```python
from swap_exceptions import swap_exceptions

@swap_exceptions({KeyError: lambda e: ValueError(f"Incorrect value {e.args[0]}")})
def get_value(key: str):
    d = {'a': 1, 'b': 2}
    return d[key]

get_value('c')  # ValueError: Incorrect value c
```
draw-with-percentage 0.0.6
Python Library to draw with percentage
License: MIT
Requires Python: >=3

### Draw with percentages
Python library for randomizing given elements with the appropriate percentage chance.

#### Example:
Sample library usage

##### Code:
```python
from draw_with_percentage import draw_with_percentage

percentages = [
    ["option1", "10"],
    ["option2", "20"],
    ["option3", "30"],
    ["option4", "40"]
]

res = draw_with_percentage(percentages)
```

##### Response:
1. Option 1 10% chance will be refunded.
2. Option 2 20% chance will be refunded.
3. Option 3 30% chance will be refunded.
4. Option 4 40% chance will be refunded.


#### Request:
```json5
[
    ["name", "percent"],
    ["name", "percent"],
    ["name", "percent"],
    ["name", "percent"]
    // etc.
]
```
##### Remember:
* In the first field we give the name of the element.
* In the second field we give the percentage written as a string.
    * We write the percentage down to **three places** after the decimal point.
* The sum of all percentages must be 100.