2

I was looking for something similar to perl's Dumper functionality in python. So after googling I found one which serves me well @ https://gist.github.com/1071857#file_dumper.pyamazon

So I downloaded and installed it and it works fine.

But then I came accross PyPI: http://pypi.python.org/pypi which looks like CPAN equivalent for python.

So I searched for the Dumper module there and I could not find it there. I was hoping that this seems like a very basic module and should have been listed in PyPI.

So my question is, if I have to install a python module, then should I search in PyPI first and if i do not find then look other places on google?

OR is there any other Python Module repository apart from PyPI?

I am learning python and hence this question.

thanks.

slayedbylucifer
  • 22,878
  • 16
  • 94
  • 123

2 Answers2

7

If you are using pip, pip search package_name would help you do the same as searching on the web interface provided by PyPi.

Once located, installing a python package is of course as easy as

pip install package_name

Some python libraries may be in development stage and may not directly be available on PyPi OR you may want a specific commit has (git) of that library and if you can find that library's source on github.com or on bitbucket.com for example, you can do

pip install -e git+git://github.com/the/repo/url.git#egg=package_name

And regarding your question about perl Dumper, perl's Dumper has two main uses iirc -

  • data persistence
  • debugging and inspecting objects.

As far as I know, there's no exact equivalent of perl's Dumper in python.

However, I use pickle for data persistence.

And pprint is useful for visually inspecting objects/debug.

Both of which are standard, built-in modules in Python. There's no necessity for 3rd party libraries for these functionalities.

If you want to use what is here - https://gist.github.com/1071857#file_dumper.pyamazon.

What you need to do is to copy the code and place it in a local file in your project directory. You can name the file something like pydumper.py. Or any name you prefer really, but end it with suffix .py.

In your project, you can import the functions and classes defined in pydumper.py by doing

from pydumper import *

or if you want to be specific (which is preferred. it's better to be explicit about what you are importing.)

from pydumper import Dumper

and you can start using the Dumper class in your own code.

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
  • I never bothered what perl's Dumper does behind the curtains. I always used it to "visualize" deep nested hashes and arrays and it had been a life Savior. so I was looking for something similar in python to "visualize" deep nested lists/dictionaries and i found in above mentioned github link. again, I am indifferent to what it does behind the curtains. – slayedbylucifer Nov 07 '12 at 04:38
  • You can use the code (which is not packaged and uploaded to pypi) using what I mentioned in my answer. – Calvin Cheng Nov 07 '12 at 04:43
1

Are you looking for something like easy_install from setuptools? I might have misunderstood your question as I don't use perl.

From the Scripts directory in the python installation directory ("c:/python27/Scripts" on my machine), you can install modules from the command line like so:

easy_install modulename

Makes life alot easier if you set the Scripts directory to your PATH variable.

Aesthete
  • 18,622
  • 6
  • 36
  • 45
  • I am looking for a place where i can find python modules. In perl, CPAN is a one stop shop for perl modules. Similarly, in python, I found PyPi for python. But a very basic module like Dumper is not listed in PyPI and I could find it on github made me wonder is PyPI the right place for me to look in case I need to install a python module. – slayedbylucifer Nov 07 '12 at 04:42
  • You should avoid using `easy_install` as far as possible. There are some libraries that need to be installed with `easy_install` but for most situations, `pip` is the right choice. – Calvin Cheng Nov 07 '12 at 07:03
  • @CalvinCheng - Yeah I've realised that after answering this question. Related here http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install – Aesthete Nov 07 '12 at 07:37