Like partial, but you can determine the order of *args
pip install flexible-partial
#######################################
Update 2022-12-04:
# When you use FlexiblePartialOwnName, you can define the output of __str__ and __repr__
from flexible_partial import FlexiblePartial, FlexiblePartialOwnName
import regex
from random import choice
from string import ascii_lowercase
text = """Hi, my friend, how are you?"""
allfus = [
FlexiblePartialOwnName(
regex.sub,
f'{x} Hello, I am a function!', # for __str__ and __repr__
True, # this_args_first = True (choice(list(ascii_lowercase)) will be the first arg when the function is called)
choice(list(ascii_lowercase)),
flags=regex.IGNORECASE,
)
for x in range(10)
]
for alsw in allfus:
print(f"Executing: {alsw}")
text = alsw("P", text)
print(text)
Executing: 0 Hello, I am a function!
Hi, my friePd, how are you?
Executing: 1 Hello, I am a function!
Hi, my friePd, how are you?
Executing: 2 Hello, I am a function!
Hi, mP friePd, how are Pou?
Executing: 3 Hello, I am a function!
Hi, mP friePd, how are Pou?
Executing: 4 Hello, I am a function!
Hi, mP friePd, hPw are PPu?
Executing: 5 Hello, I am a function!
Hi, mP friePd, hPw are PPu?
Executing: 6 Hello, I am a function!
Hi, PP friePd, hPw are PPu?
Executing: 7 Hello, I am a function!
Hi, PP friePd, hPP are PPu?
Executing: 8 Hello, I am a function!
Hi, PP friePd, hPP Pre PPu?
Executing: 9 Hello, I am a function!
Hi, PP friePd, hPP Pre PPP?
#######################################
from flexible_partial import FlexiblePartial
import regex
from random import choice
from string import ascii_lowercase
text = """Hi, my friend, how are you?"""
allfus = [
FlexiblePartial(
regex.sub,
True, # this_args_first = True (choice(list(ascii_lowercase)) will be the first arg when the function is called)
choice(list(ascii_lowercase)),
flags=regex.IGNORECASE,
)
for x in range(10)
]
for alsw in allfus:
print(f"Executing: {alsw}")
text = alsw("P", text)
print(text)
# Executing: regex.regex.sub('z', flags=regex.I)
# Hi, my friend, how are you?
# Executing: regex.regex.sub('o', flags=regex.I)
# Hi, my friend, hPw are yPu?
# Executing: regex.regex.sub('u', flags=regex.I)
# Hi, my friend, hPw are yPP?
# Executing: regex.regex.sub('y', flags=regex.I)
# Hi, mP friend, hPw are PPP?
# Executing: regex.regex.sub('z', flags=regex.I)
# Hi, mP friend, hPw are PPP?
# Executing: regex.regex.sub('b', flags=regex.I)
# Hi, mP friend, hPw are PPP?
# Executing: regex.regex.sub('k', flags=regex.I)
# Hi, mP friend, hPw are PPP?
# Executing: regex.regex.sub('w', flags=regex.I)
# Hi, mP friend, hPP are PPP?
# Executing: regex.regex.sub('k', flags=regex.I)
# Hi, mP friend, hPP are PPP?
# Executing: regex.regex.sub('a', flags=regex.I)
# Hi, mP friend, hPP Pre PPP?
text = """Hi, my friend, how are you?"""
allfus = [
FlexiblePartial(
regex.sub,
False, # this_args_first = False (text will be the last arg when the function is called)
text,
flags=regex.IGNORECASE,
)
for x in range(10)
]
for alsw in allfus:
print(f"Executing: {alsw}")
text = alsw(choice(list(ascii_lowercase)), choice(list(ascii_lowercase)))
print(text)
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, me friend, how are eou?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, mv friend, how are vou?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my friend, hos are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my frienh, how are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my friend, how are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my mriend, how are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my friend, how are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, mv friend, how are vou?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my friend, how are you?
# Executing: regex.regex.sub('Hi, my friend, how are you?', flags=regex.I)
# Hi, my friend, how rre you?
Metadata
Release files for flexible-partial 0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flexible_partial-0.12.tar.gz | 5.2 kB | Without provenance | Details for flexible_partial-0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flexible_partial-0.12-py3-none-any.whl | Python 3 | none | any | Details for flexible_partial-0.12-py3-none-any.whl |
Total release size: 11.2 kB
Release files / flexible_partial-0.12.tar.gz
| Download URL | flexible_partial-0.12.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e9441ce6198cef6906b56eb627ae1e3dd0e3434d5f0952e43dcbed70d85ab46
|
|
BLAKE2b-256 checksum How to use checksums |
318c2f4ed6bf784ceb82cb2e654616db27a08c8aee66eaf1061a4a9e8119e862
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / flexible_partial-0.12-py3-none-any.whl
| Download URL | flexible_partial-0.12-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d41d3638dc6add3086f62f2deb25c11436859bdaceea048efed0971de145e28
|
|
BLAKE2b-256 checksum How to use checksums |
5def0edafefc93745fcf5ec8035cc2271b6ea87987a8b2452c631f5e96362190
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for flexible-partial 0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.