This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pdb - print in for iteration prints None after printing
Type: Stage:
Components: Documentation, Library (Lib) Versions: Python 3.0, Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: MLModel, georg.brandl
Priority: normal Keywords:

Created on 2009-09-14 00:18 by MLModel, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg92588 - (view) Author: Mitchell Model (MLModel) Date: 2009-09-14 00:18
Near the bottom of the library documentation for pdb there is an example
of a very useful alias:

alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])

It turns out that doing print in a for loop in pdb results in None being
printed on a line after each print. For example:

(Pdb) 
for n in range(3): print(n)
0
None
1
None
2
None
(Pdb) 

Seems like a (minor) bug, but if not, the example should be removed or
replaced in the documentation.
msg92675 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-09-16 09:56
This is caused by the special displayhook that pdb uses.

Normally, the displayhook suppresses output when it would print None;
this is not done in pdb's displayhook. This was a conscious decision,
because it can remove confusion when you try to get variable values like
this:

(Pdb) foo
(Pdb)

I'll ask python-dev for what is preferred.
msg92699 - (view) Author: Mitchell Model (MLModel) Date: 2009-09-16 16:28
No problem with the None's -- I see your point about that. Just that  
maybe the alias example should point out that the Nones will be  
printed so people won't be surprised and try to figure out what's wrong.

     --- Mitchell

On Sep 16, 2009, at 5:56 AM, Georg Brandl wrote:

>
> Georg Brandl <georg@python.org> added the comment:
>
> This is caused by the special displayhook that pdb uses.
>
> Normally, the displayhook suppresses output when it would print None;
> this is not done in pdb's displayhook. This was a conscious decision,
> because it can remove confusion when you try to get variable values  
> like
> this:
>
> (Pdb) foo
> (Pdb)
>
> I'll ask python-dev for what is preferred.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue6903>
> _______________________________________
msg92700 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-09-16 16:36
Actually, Guido hates the Nones. :)  Fixed in r74839.
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51152
2009-09-16 16:36:52georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg92700
2009-09-16 16:28:53MLModelsetmessages: + msg92699
2009-09-16 09:56:01georg.brandlsetmessages: + msg92675
2009-09-14 00:18:24MLModelcreate