Include the variable name in print statements
Project description
smartprint
Save a few seconds and a few keystrokes with every print statement! 😎
Usual print statment:
print ("veryLongVariableName : ", veryLongVariableName)
Enter smart print:
from smartprint import smartprint as sprint
veryLongVariableName = 25
sprint (veryLongVariableName)
Output:
veryLongVariableName : 25
Examples:
1. smartprint works with multiple variables and different kinds of objects
from smartprint import smartprint as sprint
import numpy as np
a = [1,22,31]
sprint (a, len(a))
sprint (np.random.rand())
Output:
a, len(a) : [1, 22, 31] 3
np.random.rand() : 0.649617730484109
2. Now, smartprint
includes pretty print (through pprint
module) for lists and dicts as shown below:
2 (a) List example
a = [1, 4, 5, 3, 4, "This", "is", \
["fun; The inspect module is"], \
"really powerful","What",["do", [9, 8, 6],"you", "think?", 5]]
sprint (a)
Output:
List: a
[1,
4,
5,
3,
4,
'This',
'is',
['fun; The inspect module is'],
'really powerful',
'What',
['do', [9, 8, 6], 'you', 'think?', 5]]
2 (b) Dict example
a = {1:2, 3:"Kumar",31:"Nishant", \
2.5:{1:2, 3:"Kumar",31:"Nishant", 0:"NK"}, 0:"NK"}
sprint (a)
Output:
Dict: a
Key: Value
{0: 'NK',
1: 2,
2.5: {0: 'NK', 1: 2, 3: 'Kumar', 31: 'Nishant'},
3: 'Kumar',
31: 'Nishant'}
In place print replacement
As suggested by user @nickdelgrosso in Issue 7, if
from smartprint import smartprint as print
is used, smartprint can be used as an in-place print replacement. Alternatively, it can be used to override the existing print statements without touching any other parts of the code.
Installation
pip install smartprint
Issues
Please feel free to start a pull request/ raise an issue.
Code coverage plot
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
smartprint-1.0.4.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for smartprint-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94a2d6edc212b5ad14f10c3b48b325f3d253d88ac70354993939e6c412102bb6 |
|
MD5 | c2cf6cc8990052b7d6c568204f85f309 |
|
BLAKE2b-256 | 152bcaa9d4c9fc3e05691b786a2077af50569c6aad452b2be83dc0f610c2ca2f |