Loax Loax - 1 year ago 101
Python Question

Possible bug in pdb module in Python 3 when using list generators

After running this code in Python 3:

import pdb

def foo():
nums = [1, 2, 3]
a = 5


The following expressions work:

(Pdb) print(nums)
[1, 2, 3]

(Pdb) print(a)

(Pdb) [x for x in nums]
[1, 2, 3]

but the following expression fails:

(Pdb) [x*a for x in nums]
*** NameError: global name 'a' is not defined

The above works fine in Python 2.7.

Is this a bug or I am missing something?

Update: See the new accepted answer. This has been a bug and has been addressed now.

Answer Source

if you type interact in your [i]pdb session, you get an interactive session, and list comprehensions do work as expected in this mode

source: http://bugs.python.org/msg215963

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download