A simple debugging tool for printing script and function names
Project description
Bandit
A lightweight Python library for debugging and logging, providing tools to retrieve script and function names dynamically. Ideal for quick insights into code execution without heavy dependencies.
Installation
Install bandit-log from PyPI:
pip install bandit-log
Features
- Retrieve the current script name and function name with simple static methods.
- Use a decorator to log execution details automatically.
- No external dependencies, pure Python.
Usage
Here’s a quick example to get you started:
from bandit_log.bandit import Bandit
# Decorate a function to log its name
@Bandit.universal_print(show_script=False)
def power_of_five(n):
return 5 ** n
# Call the function
print(power_of_five(3)) # Outputs: "Func: power_of_five" followed by 125
# Get script and function names manually
script, func = Bandit.names()
print(f"Running in {script}, called from {func}")
API Reference
Bandit.universal_print(show_script=True, show_func=True)
A decorator that prints the script name and/or function name before executing the function.
- Arguments:
show_script(bool): IfTrue, prints the script name. Default:True.show_func(bool): IfTrue, prints the function name. Default:True.
- Example:
@Bandit.universal_print(show_script=False) def my_func(): print("Hello!") my_func() # Outputs: "Func: my_func" then "Hello!"
Bandit.names()
Returns a tuple of the current script name and the calling function name.
- Returns:
(script_name, function_name) - Example:
script, func = Bandit.names() print(script, func) # e.g., "example.py some_function"
Bandit.func_name()
Returns the name of the calling function.
- Returns:
str - Example:
def test(): print(Bandit.func_name()) # Outputs: "test" test()
Bandit.script_name()
Returns the name of the current script.
- Returns:
str - Example:
print(Bandit.script_name()) # e.g., "example.py"
Requirements
- Python 3.7 or higher
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Feel free to open issues or submit pull requests on GitHub.
Made with ❤️ by somke
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bandit_log-0.1.2.tar.gz.
File metadata
- Download URL: bandit_log-0.1.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee5e1dea8d4212f9306d202b01f39d7f3825196ff1fc52989e0c52a9b22a5d23
|
|
| MD5 |
218592d835e5b29838363bd3697fbbbc
|
|
| BLAKE2b-256 |
844b200c173840ad888aa43f6a7a0805f69971168e1350894acd5afb135d9146
|
File details
Details for the file bandit_log-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bandit_log-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52083356744a5d5268e0e8629d3f02dd6b91838377b6be7c7e4b13e157719c06
|
|
| MD5 |
55fb10d455afbd2d2938d2321c433e5b
|
|
| BLAKE2b-256 |
f6b06fe078f054ec79d503923e4c119b0d710caa6e2f0370dcebc58fb32684b6
|