Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sha256/python-var-dump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

37 Commits

Repository files navigation

var_dump

for python


var_dump is a PHP's var_dump() equivalent function for python. It displays structured information such as type, value etc of a python object, list, tuple, dict & other types.

Installation


using pip

pip install var_dump

Or

clone the project & cd into the python-var-dump directory then run:

python setup.py install

Examples


Example #1:

from var_dump import var_dump
var_dump(123) 					# output: #0 int(123)
var_dump(123.44) 				# output: #0 float(123.44)
var_dump("this is a string") 	# output: #0 str(16) "this is a string"
var_dump(None) # output: 		# output: #0 NoneType(None)
var_dump(True) # output 		# output: #0 bool(True)

Example #2:

you can pass more than one argument:

from var_dump import var_dump
var_dump(123, 123.44, None, False)

Output:

#0 int(123) 
#1 float(123.44) 
#2 NoneType(None) 
#3 bool(False) 

Example #3:

from var_dump import var_dump
class Base(object):
 def __init__(self):
 self.baseProp = (33, 44)
		self.fl = 44.33
class Bar(object):
 def __init__(self):
 self.barProp = "I'm from Bar class"
		self.boo = True
class Foo(Base):
 def __init__(self):
 super(Foo, self).__init__()
 self.someList = ['foo', 'goo']
 self.someTuple = (33, (23, 44), 55)
 self.anOb = Bar()
		self.no = None
foo = Foo()
var_dump(foo)

Output

#0 object(Foo) (6)
 baseProp => tuple(2) 
 [0] => int(33) 
 [1] => int(44) 
 someTuple => tuple(3) 
 [0] => int(33) 
 [1] => tuple(2) 
 [0] => int(23) 
 [1] => int(44) 
 [2] => int(55) 
 no => NoneType(None) 
 someList => list(2) 
 [0] => str(3) "foo"
 [1] => str(3) "goo"
 fl => float(44.33) 
 anOb => object(Bar) (2)
 boo => bool(True) 
 barProp => str(18) "I'm from Bar class"

Unit tests


Tests are written using unittest.

Run them with python -m unittest tests.


License: BSD License

About

PHP's var_dump equivalent function for Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages

AltStyle によって変換されたページ (->オリジナル) /