Rand Stats

Pyrint

zef:witawayar

Pyrint

Print like a Pythoneer: a &pyrint subroutine with sep and end keyword arguments which otherwise behaves as &say

use Pyrint;

# Arguments are separated by a space by default
say    3, 4, 5;  # 345\n
pyrint 3, 4, 5;  # 3 4 5\n

# Can specify how to separate them
pyrint "Id", "Date", "Value", sep => ", ";  # Id, Date, Value\n

# Also what to put at the end (newline by default)
pyrint "Tab", "after", "these", end => "\t";  # Tab after these\t

.WHY, .WHAT

I sometimes find myself frustrated when the arguments to &say are printed by concatenating them together, with no space in between (same applies for &put and &print too). Less often occurs is to customize what to print after the arguments, which is newline by default but I remember needing, e.g., tabs instead. So, to this end, we mimic Python's print built-in with its sep and end keyword arguments to customize separation and ending in printing.

Only one subroutine is exported: &pyrint, with signature (*@args, :$sep = " ", :$end = "\n"). It is imported by default, i.e., available with use Pyrint; but if wanted, can also specify with a tag, i.e., use Pyrint :pyrint; to better see in a large program what comes from where. It calls .gist on the arguments to print like the built-in &say.

Installation

Using pakku:

pakku add Pyrint