On Saturday 12 December 2009 04:52:26 am Gabriel Genellina wrote: > En Fri, 11 Dec 2009 19:11:38 -0300, Sancar Saran <sancar.sa...@evodot.com> > > escribió: > > In php we had print_r function to see entire array structure. After some > > search I found some equal module named pprint. > > > > And some how this module wont work with mod_wsgi it was something about > > mod_wsgi portability standards. > > > > After some research there where some thing about putting some variables > > in > > apache config to disable this. > > > > And now I can see some dictionary structure in my apache log and I got > > some > > errors like > > r += pprint.pprint(self.data) > > TypeError: cannot concatenate 'str' and 'NoneType' objects > > The pprint function in the pprint module (that is, pprint.pprint) *prints* > its argument, and returns nothing -- or, better said, it returns None > (same as print_r in PHP, without the return parameter set to true) > > > So is there any way to get dictionary structure in string format ? > > You don't need anything special for that. There are two built-in functions > that convert any object to string: str and repr. str(x) provides a simple > representation of x (whatever it is), and repr(x) provides a more > technical view; when possible, eval(repr(x)) should return x. > For debugging purposes, repr() is your friend. > pprint.pformat is like the built-in repr(), but provides a better > formatted representation, with indenting, a maximum width, etc. > > > Another question is. When I import a module from top is it available for > > later > > imported modules > > Each module contains its own, separate namespace. If you `import foo` in > some module, the name `foo` becomes available to be used in that module -- > if you want to use `foo` in another module, you have to `import foo` in > that other module too. > > Don't worry; after the very first import (which involves locating the > module, loading and compiling it if necesary, and writing the .pyc file) > any subsequent imports of the same module just return a new reference to > the existing, in-memory module object. > Hello Gabriel,
Thanks for support. repr works as you say and I had some complaints, it wont format the output. Finding some string in 100 key dictionary in formatted in single line bit problematic. Is it any way to format it ? Also, very interesting things are happen. def debug(self): r = '<pre>' r += repr(self.data) r += '</pre>' return r following code works and does not work ever reload ? One time work another reload wont work. What I missing ? And is possible to get this ? (I store the environ here) r += repr(self.data['environ']['mod_wsgi.listener_port']) or similar multi sub level elements ? Regards... -- http://mail.python.org/mailman/listinfo/python-list