print is not a function

Karl Scalet news at yebu.de
Wed Oct 8 11:15:30 EDT 2003


Karl Scalet wrote:

> Hi,
> 
> quite often there is a need to just print out the items of a list.
> 
> [ prt(x) for x in my_list ]
> 
....

Thank you all for the overwhelming sympathy to my original problem :-)

To clarify a bit:

I'm no fan of unreadable oneliners, normally, or making things more
complicated as they are.
I was just looking for the easiest way to *inspect*
*interactively* lists, dictionaries.
Evaluating such a list via
 >>> print my_list
or even
 >>> my_list
does not give very readable results, especially if those
lists tend to become longer.

So my own (best??) solution is:

 >>> from pprint import pprint as prt # cannot overcome this line :-(
 >>> from qt import * # now the secret unveils
 >>> [ prt(x) for x in locals() if x[:2]=='QA' ]
# sorry Signore Alex, but it's shorter than startswith :-)
# gives me
 >>> 'QAssistantClient'
 >>> 'QAccel'
 >>> 'QActionGroup
 >>> 'QApplication'
 >>> 'QAction'
 >>> [None, None, None, None, None] # well, I can live with

In the case of doing such interactive inspections, i don't
mind about potential side-effects, i actually don't see them here.

Karl

PS:
I *did* write my own little helper functions for such things,
but then, you are in a different environment, and write the
helpis again and again.





More information about the Python-list mailing list