Python-printr is a module that allows to emulate theprint_r()
function of PHP by printing the objects properties of a class instance and its internal structure. If you need to useprintr()
function for list, tuples and dicts, please, don't useprintr()
function. You can choosepprint
module.printr()
function is only for objects of your own class instances.
You can copy the source code on your own
printr.py
file or download file
from this link.
Developed by Eugenia Bahit
(Software Architect, GLAMP Teacher & Agile Coach).
Distributed under a GPL v3.0
licence.
printr
is a module that allows to emulate the
print_r()
function of PHP by
printing the objects properties of a class instance and its internal
structure.
First, you must get an object of a class instance and then,
you can call to the printr
function by passing the object
like an argument function.
Example:
# -*- coding: utf-8 -*- class Vidrio(object): def __init__(self): self.color = '' class Marco(object): def __init__(self): self.color = '' self.material = '' self.vidrio = Vidrio() class Ventana(object): def __init__(self): self.posicion = '' self.marco = Marco() from printr import printr ventana = Ventana() printr(ventana) Returns: <Ventana object> { posicion: '' marco: <Marco object> { color: '' vidrio: <Vidrio object> { color: '' } material: '' } }
You can set the character using for identation.
By default is white space. Change this value by modifying the
IDENTATION_CHAR
constant:
import printr printr.IDENTATION_CHAR = "." # use point to identation myobject = MyClass() printr.printr(myobject)
Also, you can set the identation width, by
modifying the TAB_WIDTH
constant (by default is 4):
import printr printr.TAB_WIDTH = 2 myobject = MyClass() printr.printr(myobject)