dom_beau
dom_beau

Reputation: 2497

Access to class members within ipdb

Maybe this question will look simple but I'm trying to look at some member variables from within ipdb and I cannot see how.

Example:

class MyClass( object ):
    def __init__( self, p ):
        self.__p = p
        pass                   # <--- breakpoint here!

I am sure that p is correct. In the debugger I enter:

ipdb> (self.__p)

and I get the following error message:

* * *AttributeError: 'MyClass' object has no attribute '__p'

It seems that self is the class, not the instance for the debugger.

Any idea about how to perform what I do?

I use Python 2.7.3 on IPython 0.12.1 on Kubuntu 12.04 - 64 bits.

Upvotes: 1

Views: 870

Answers (2)

ssoler
ssoler

Reputation: 5264

To give visibility to @dom_beau's comment, I repost its commnent as an answer.

The way to access "private" class members in ipdb is:

ipdb> (self._MyClass__p)

Upvotes: 0

Miki Tebeka
Miki Tebeka

Reputation: 13850

See here for the reason, this is Pythons way of having "private" variables.

Upvotes: 2

Related Questions