rv
Utils to work with randomness
To install: pip install rv
Examples
random_word
Make a random word by concatenating randomly drawn elements from alphabet together
>>> t = random_word(4, 'abcde'); # e.g. 'acae'
>>> t = random_word(5, ['a', 'b', 'c']); # e.g. 'cabba'
>>> t = random_word(4, [[1, 2, 3], [40, 50], [600], [7000]]); # e.g. [40, 50, 7000, 7000, 1, 2, 3]
>>> t = random_word(4, [1, 2, 3, 4]); # e.g. 13 (because adding numbers...)
>>> # ... sometimes it's what you want:
>>> t = random_word(4, [2 ** x for x in range(8)]); # e.g. 105 (binary combination)
>>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: str(x) + str(y)); # e.g. '4213'
>>> t = random_word(4, [1, 2, 3, 4], concat_func=lambda x, y: int(str(x) + str(y))); # e.g. 3432
random_romatted_str_gen
Random formatted string generator
The following will be made not random (by restricting the constraints to "no choice". This is so that we get consistent outputs to assert for the doc test.
>>> list(random_formatted_str_gen('root/{}/{}_{}.test', (2, 5), 'abc', n=5))
[('root/acba/bb_abc.test',),
('root/abcb/cbbc_ca.test',),
('root/ac/ac_cc.test',),
('root/aacc/ccbb_ab.test',),
('root/aab/abb_cbab.test',)]
Example with automatic specification:
>>> list(random_formatted_str_gen('root/{}/{}_{}.test', (3, 4), 'a', n=2))
[('root/aaa/aaa_aaa.test',), ('root/aaa/aaa_aaa.test',)]
Example with manual specification
>>> list(random_formatted_str_gen('indexed field: {0}: named field: {name}', (2, 3), 'z', n=1))
[('indexed field: zz: named field: zz',)]
Utils
Get the "parameter" indices/names of the format_string
>>> from rv import format_params_in_str_format
>>> format_string = '{0} (no 1) {2}, and {0} is a duplicate, {} is unnamed and {name} is string-named'
>>> format_params_in_str_format(format_string)
[0, 2, 0, None, 'name']
Metadata
Release files for rv 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rv-0.0.8.tar.gz | 9.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rv-0.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.7 kB
Release files / rv-0.0.8.tar.gz
| Download URL | rv-0.0.8.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b65cdfb04c42918e815a80a38ec4dd048588daa22158218686d62cef29617f6e
|
|
BLAKE2b-256 checksum How to use checksums |
11b4ea2172ca2996f976bacbf2fbb25fed420531cf97008049925566bd999437
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rv-0.0.8-py3-none-any.whl
| Download URL | rv-0.0.8-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbf548e87133bb54141d44192559b6df0f1d103aefb36c26bcbba96d06d85786
|
|
BLAKE2b-256 checksum How to use checksums |
4afdde0a96549c0c2f8d9d0a629e30a53f85c87a2eb660ab0c006410b85fab80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|