Enhanced print function with timestamping, styling, and color options.
Project description
printc: Enhanced Print Function for Python
printc
is an enhanced print function for Python that provides additional features such as timestamping, text styling, colored output, and improved error handling, offering more flexibility and customization options compared to the standard print
function.
Features
- Timestamps: Optionally prepend messages with timestamps.
- Prefixes: Add customizable prefixes to messages for better categorization.
- Text Styling: Support for bold and underline text styles.
- Text Coloring: Ability to print text in various colors for visual differentiation.
- File Output: Direct output to both standard streams (
sys.stdout
,sys.stderr
) and files for logging purposes. - Flexible Parameters: Customize output behavior with parameters like
sep
,end
,flush
, etc. - Robust Error Handling: Handles errors gracefully during timestamp formatting, file operations, and general printing.
Installation
You can install printc
from PyPI using pip:
pip install printc
Usage
from printc import printc
# Basic usage
printc("Hello", "World", sep="-", end="!\n")
# Adding timestamps
printc("Logging message", timestamp=True)
# Adding prefixes
printc("Error", "File not found", prefix="ERROR")
# Styling text
printc("Bold text", style="bold")
printc("Underlined text", style="underline")
# Coloring text (requires colorama package)
printc("Red text", color="RED")
printc("Blue text", color="BLUE")
# Output to a file
printc("Log entry", file="output.log")
# Customized usage with all options
printc("Detailed log entry", timestamp=True, prefix="INFO", style="bold", color="GREEN", file="output.log", flush=True)
Parameters
*args
: Variable length arguments to print.sep
: Separator between arguments (default is" "
).end
: Ending character(s) at the end of the printed line (default is"\n"
).file
: Output stream (None
for standard output, file path for file output).flush
: Whether to flush the output stream (default isFalse
).timestamp
: Whether to prepend messages with timestamps (default isFalse
).prefix
: Prefix string for messages (default isNone
).color
: Text color (requirescolorama
package).style
: Text style (bold
,underline
, orNone
for normal text).**kwargs
: Additional keyword arguments passed to the underlyingprint
function.
Dependencies
colorama
: Required for text coloring (automatically installed withpip
).
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by the need for enhanced printing capabilities in Python applications.
Notes:
- Dependencies: Ensure to mention dependencies like
colorama
and include instructions for installation if not automatically handled bypip
. - Examples: Provide various examples demonstrating different features and combinations of parameters to illustrate usage scenarios effectively.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycprint-1.0.0.tar.gz
(3.3 kB
view hashes)