FAQ
Guys,

I have some problem changing method locals with pdb:

import pdb

def test():
foo = 'foo'
pdb.set_trace()

test()
--Return--
/home/jeanmichel/trunk/tnt/test.py(5)test()->None
-> pdb.set_trace()
(Pdb) print foo
foo
(Pdb) foo = 'bar'
(Pdb) print foo
foo
(Pdb)


I tried using locals() but it returns a copy of the locals. So changing
locals['foo'] won't do any good.
(Pdb) locals()
Out[6]: {'__return__': None, 'foo': 'foo'}


Any idea ? I'm starting to wonder if it is possible.

JM

Search Discussions

  • Diez B. Roggisch at Dec 10, 2009 at 1:04 pm

    Jean-Michel Pichavant wrote:

    Guys,

    I have some problem changing method locals with pdb:

    import pdb

    def test():
    foo = 'foo'
    pdb.set_trace()

    test()
    --Return--
    /home/jeanmichel/trunk/tnt/test.py(5)test()->None
    -> pdb.set_trace()
    (Pdb) print foo
    foo
    (Pdb) foo = 'bar'
    (Pdb) print foo
    foo
    (Pdb)


    I tried using locals() but it returns a copy of the locals. So changing
    locals['foo'] won't do any good.
    (Pdb) locals()
    Out[6]: {'__return__': None, 'foo': 'foo'}


    Any idea ? I'm starting to wonder if it is possible.
    I recall having some issues with local variables sometimes, but actually
    your example works fine for me:



    def test():
    foo = "foo"


    import pdb; pdb.set_trace()

    print foo

    test()


    And the session:

    $ python /tmp/test.py
    /tmp/test.py(9)test()
    -> print foo
    (Pdb) pp foo
    'foo'
    (Pdb) foo = "bar"
    (Pdb) n
    bar
    --Return--
    /tmp/test.py(9)test()->None
    -> print foo
    (Pdb) c


    Diez
  • Jean-Michel Pichavant at Dec 10, 2009 at 1:37 pm

    Diez B. Roggisch wrote:
    Jean-Michel Pichavant wrote:

    Guys,

    I have some problem changing method locals with pdb:

    import pdb

    def test():
    foo = 'foo'
    pdb.set_trace()

    test()
    --Return--
    /home/jeanmichel/trunk/tnt/test.py(5)test()->None
    -> pdb.set_trace()
    (Pdb) print foo
    foo
    (Pdb) foo = 'bar'
    (Pdb) print foo
    foo
    (Pdb)


    I tried using locals() but it returns a copy of the locals. So changing
    locals['foo'] won't do any good.
    (Pdb) locals()
    Out[6]: {'__return__': None, 'foo': 'foo'}


    Any idea ? I'm starting to wonder if it is possible.
    I recall having some issues with local variables sometimes, but actually
    your example works fine for me:



    def test():
    foo = "foo"


    import pdb; pdb.set_trace()

    print foo

    test()


    And the session:

    $ python /tmp/test.py
    /tmp/test.py(9)test()
    -> print foo
    (Pdb) pp foo
    'foo'
    (Pdb) foo = "bar"
    (Pdb) n
    bar
    --Return--
    /tmp/test.py(9)test()->None
    -> print foo
    (Pdb) c


    Diez
    You're right, it can work, eventually...

    Take a look at sessions below:

    def test():
    foo = 'foo'
    pdb.set_trace()
    print 'This is the test method displaying foo:', foo

    In [3]: test()
    /home/jeanmichel/trunk/tnt/test.py(6)test()
    -> print 'This is the test method displaying foo:', foo
    (Pdb) foo='bar'
    (Pdb) c
    This is the test method displaying foo: bar

    In [5]: test()
    /home/jeanmichel/trunk/tnt/test.py(6)test()
    -> print 'This is the test method displaying foo:', foo
    (Pdb) foo='bar'
    (Pdb) print foo
    foo
    (Pdb) c
    This is the test method displaying foo: foo

    By just inserting the print foo statement right after changing foo's
    value, I've rolled back the value to 'foo' ??? A hell of a wtf pdb feature !

    JM

    PS : using python 2.5
  • Lie Ryan at Dec 10, 2009 at 9:02 pm

    On 12/11/2009 12:37 AM, Jean-Michel Pichavant wrote:
    Diez B. Roggisch wrote:
    By just inserting the print foo statement right after changing foo's
    value, I've rolled back the value to 'foo' ??? A hell of a wtf pdb
    feature !
    Apparently it's fixed in 2.7 and 3.1

    D:\Lie Ryan\Desktop>python27 d.py
    d:\lie ryan\desktop\d.py(6)test()
    -> print(foo)
    (Pdb) foo = "bar"
    (Pdb) pp foo
    'bar'
    (Pdb) c
    bar

    D:\Lie Ryan\Desktop>python27 d.py
    d:\lie ryan\desktop\d.py(6)test()
    -> print(foo)
    (Pdb) foo = "bar"
    (Pdb) c
    bar
  • Jean-Michel Pichavant at Dec 11, 2009 at 12:29 pm

    Lie Ryan wrote:
    On 12/11/2009 12:37 AM, Jean-Michel Pichavant wrote:
    Diez B. Roggisch wrote:
    By just inserting the print foo statement right after changing foo's
    value, I've rolled back the value to 'foo' ??? A hell of a wtf pdb
    feature !
    Apparently it's fixed in 2.7 and 3.1

    D:\Lie Ryan\Desktop>python27 d.py
    d:\lie ryan\desktop\d.py(6)test()
    -> print(foo)
    (Pdb) foo = "bar"
    (Pdb) pp foo
    'bar'
    (Pdb) c
    bar

    D:\Lie Ryan\Desktop>python27 d.py
    d:\lie ryan\desktop\d.py(6)test()
    -> print(foo)
    (Pdb) foo = "bar"
    (Pdb) c
    bar
    Thanks, that could mean it is a bug from pdb in python 2.5. I tried with
    ipython & python, same issue. I'll keep that in mind, sadly it concerns
    a basic feature of the debugger.

    JM

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 10, '09 at 12:57p
activeDec 11, '09 at 12:29p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase