Re: Problems with debugging Lists



On Saturday 12 December 2009 04:52:26 am Gabriel Genellina wrote:
En Fri, 11 Dec 2009 19:11:38 -0300, Sancar Saran <sancar.saran@xxxxxxxxxx>

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...
.



Relevant Pages

  • Re: How do I properly use the open office page break?
    ... S> I'm trying to intake a bunch of text and format it for open office but ... S> I can't find out why it wont work ...
    (comp.lang.perl.misc)
  • Re: datevalue
    ... Your first two values were within single quotes and hence they wont work. ... On the third format, am not sure of the reason why it doesnt work, but your date format should be in sync with your default date format set in the Regional settings. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: "Currency" format lost in subform.
    ... As far as I can recall, you would need to use the format function to force ... the format in the underlying query for the combobox or the list box. ... It wont work when it is a subform it seems. ...
    (microsoft.public.access.queries)
  • Help with Date formats
    ... Dates were suplied in 4-21-1998 format. ... I need to calc the ... but the formula =MONTH-MONTHwont work. ... or change the date format of the supplied data? ...
    (microsoft.public.excel.misc)
  • Re: Date Format
    ... wont work, keep the timestamp format mm/dd/yyy hh:ss. ... TIMESTAMP the field display correctly, but all the calculation that I ...
    (comp.databases.filemaker)