Logger module in python

S

smilesonisamal

Hi,
I am a newbie in python. I am looking for a existing module which I can import in my program to log the objects to a file?

I know there is a module Data::Dumper in perl which dumps the objects to file. But not sure about python.

Can anybody help me in this regard?

Regards
Pradeep
 
P

Paul Smith

can import in my program to log the objects to a file?
objects to file. But not sure about python.

http://docs.python.org/3/library/logging.html

That's not what the OP wants.

Pradeep, if you want to dump data for debugging take a look at the
pprint module; for example:

http://docs.python.org/3.3/library/pprint.html

If you want to store Python objects in files and read them later, most
people seem to use pickle for that:

http://docs.python.org/3.3/library/pickle.html

Others translate into another format.

See this SO question for some other suggestions:

http://stackoverflow.com/questions/2540567/is-there-a-python-equivalent-to-perls-datadumper
 
R

Roy Smith

Hi,
I am a newbie in python. I am looking for a existing module which I can
import in my program to log the objects to a file?

I know there is a module Data::Dumper in perl which dumps the objects to
file. But not sure about python.


You're talking about what's known as serializing an object. Taking the
in-memory representation and turning it into something that can be
written into a network connection or into a file, then read back in, and
turned back into an in-memory object.

The standard way to do this in Python is pickle
(http://docs.python.org/2/library/pickle.html). Depending on the type
of data you have, you might want to use JSON encoding instead
(http://docs.python.org/2/library/json.html), but pickle is probably the
most similar to Data::Dumper.
 
R

rusi

Hi,
I am a newbie in python. I am looking for a existing module which I can import in my program to log the objects to a file?
I know there is a module Data::Dumper in perl which dumps the objects to file. But not sure about python.

Assuming you are looking for a serialization format:
If efficiency, easily-at-hand, standard are important then
pickle better than json better than yaml

If however readability of the output (as the word 'log' suggests) is desired
its the other way round: yaml is the most readable, pickle is utterly unreadable
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top