Skip to main content

Include the variable name in print statements

Project description

Python application Upload Python Package codecov Code style: black Downloads

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

drawing

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

smartprint-1.0.3.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

smartprint-1.0.3-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page