Skip to main content

The easy way to inspect variables in Python

Project description

easierlog: the easy way to inspect variables in Python

Python GitHub Workflow Status (event) PyPI Downloads CodeFactor

Overview

easierlog provides an easier, but much more powerful replacement for print() function when debugging in Python.

Installation

To install the latest release, type:

$ pip install easierlog

Getting Started

Roughly every software developer needs to check how variables behave in runtime. In Python, this can be done by using print() function, that prints out the value of the passed variable. Sometimes, instead, the variable value is not enough. This is specially true when there are many variables to be inspected, or even when the same variable needs to be inspected in many parts of the code.

To inspect both variable name and value, print() is not so straightforward:

print('some_variable =', some_variable)

It became a little bit easier since Python 3.8:

print(f'{some_variable=}')

But not so easy when comparing to easierlog:

log(some_variable)

This can better understood in the script:

 1  # script1.py
 2  
 3  def function1():
 4      a = 4
 5      print(a)
 6
 7
 8  def function2():
 9      a = 3
10      b = 'Hello World'
11      print(a)
12      print(b)
13
14
15  function1()
16  function2()
17

Running the script above, it will result:

4
3
Hello World

Basic usage

By using easierlog, the previous script would become:

 1  # script2.py
 2  
 3  from easierlog import log
 4  
 5
 6  def function1():
 7      a = 4
 8      log(a)
 9 
10  
11  def function2():
12      a = 3
13      b = 'Hello World'
14      log(a)
15      log(b)
16
17
18  function1()
19  function2()
20

Running the script above, it will result:

[script2.py (line 08) in function1] (int) a = 4
[script2.py (line 14) in function2] (int) a = 3
[script2.py (line 15) in function2] (str) b = 'Hello World'

As shown above, log() provides information about where it was called:

  • File name
  • Line number
  • Function name

And about the variable passed as argument:

  • Variable type
  • Variable name
  • Variable value

Multiple variables

It is also possible to pass multiple variables at once:

 1  # script3.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log(x, y, z)
11
12 
13  function()
14

It will result:

[script3.py (line 10) in function] (float) x = 2.3
[script3.py (line 10) in function] (float) y = 1.5
[script3.py (line 10) in function] (float) z = 0.1

All variables

Calling log() without any arguments it will log all declared variables in the function:

 1  # script4.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log()
11
12 
13  function()
14

It will result:

[script4.py (line 10) in function] (float) x = 2.3
[script4.py (line 10) in function] (float) y = 1.5
[script4.py (line 10) in function] (float) z = 0.1

Expressions

Not only variables can be passed to log() function. Expressions also work:

 1  # script5.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log(x + y + z)
12 
13  function()
14

It will result:

[script5.py (line 10) in function] (float) x + y + z = 3.9

License

This package is released under MIT License.

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

easierlog-1.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easierlog-1.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file easierlog-1.1.1.tar.gz.

File metadata

  • Download URL: easierlog-1.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for easierlog-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4b6c5837562d9eabb9cb713eaa279716313f2eddbab70b9ff1c23a2211fad310
MD5 4f2e5151a700e8fa68b7be6299d67716
BLAKE2b-256 11d0924bc05ac318602ee116a985054e286d046d92b3fed3db8cb01422bc272d

See more details on using hashes here.

File details

Details for the file easierlog-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: easierlog-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for easierlog-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f69b7b6ed9fe3c789dedaa920502cfa7a2cfd926256b74e00c2e5566e09dcbd3
MD5 dafe2b94523085e11e452ba105bce2bb
BLAKE2b-256 620545b4f503fff085dcc611e363d16e286521130576466df08b39f8edd54921

See more details on using hashes here.

Supported by

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