print-once
print-once is a lightweight Python package designed to help you control the output of specific messages and function calls in your code. It ensures that messages are printed only a limited number of times, which can be useful for reducing console clutter and ensuring unique notifications.
It's well-suited for certain debugging scenarios, such as printing tensor or hyperparameter information only on the first step or the first call during deep learning training.
Installation
Install print-once via pip:
pip install print-once
Usage
print_once
Use print_once as an alternative to print. It will display a message only once, or a specified number of times.
from print_once import print_once
for i in range(100):
print_once(f"called {i}") # This line will be printed only once
for i in range(10, 20):
print_once(f"called {i}", max_times=3) # This line is printed up to 3 times
In the example above, the output will be:
called 0
called 10
called 11
called 12
Note: print_once identifies unique calls based on file path and line number, so calls on different lines will be treated separately. You can understand it as that each line using print_once will execute only once.
call_once
It also provides a call_once function to ensure a custom function is executed only once.
from print_once import call_once
def my_func(x, y):
print(f'{x} + {y} = {x + y}')
for i in range(100):
# `my_func` will be called only once
call_once(my_func, i, i + 1)
The result will be:
0 + 1 = 1
Metadata
Release files for print-once 0.0.2
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 |
|---|---|---|---|---|
| print_once-0.0.2.tar.gz | 2.5 kB | Without provenance | Details for print_once-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| print_once-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for print_once-0.0.2-py3-none-any.whl |
Total release size: 5.1 kB
Release files / print_once-0.0.2.tar.gz
| Download URL | print_once-0.0.2.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c736b0731296df4c200d0b471e40f8ab42b9b4c617cca24d2e53d325feaf3a9a
|
|
BLAKE2b-256 checksum How to use checksums |
aa9490a51f9761d75ce0f53ee28f5dff109f0df04ad9ecc11012c3450439a384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / print_once-0.0.2-py3-none-any.whl
| Download URL | print_once-0.0.2-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22edba907277782d45b30e22ad2ced0961c9d2f4b9da3a3cef5852096845dd39
|
|
BLAKE2b-256 checksum How to use checksums |
5e626c4361ed9ca1468deb12585e7abe60c610c8b43707a01a29d41d0340a397
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for print-once 0.0.2
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.