I'm somewhat new to OOP in Python (and Python in general), and I'm running into an issue when I try to access an instances private property from within one of the methods, and using a string as the property name.

The goal here is to basically have a list of properties that will be displayed (in a *key - value* format) when the objects getDetails() method is called. And it works fine, as long as all of the properties in the list are not private properties in the object. If all of the properties are *not* private, then it seems to work fine.

In the below example, you can see I have 3 properties, `foo`, `_bar` and `__baz`. In the `TheClass.getDetails()` method, if the `__baz` line is commented out, it works perfectly fine:

```py
class TheClass(object):
    def __init__( self ):
        self.foo   = 'One..'
        self._bar  = 'Two..'
        self.__baz = 'Three..'

    def getDetails( self ):
        display = [ 
            'foo'
            ,'_bar'
            #,'__baz'
        ]

        print "DebugInfo:"
        for key in display:
            print '{0:<15}: {1:<20}'.format(key, self.__dict__[ key ] or 'N/A')

TheClass().getDetails()

""" Output:
DebugInfo:
foo            : One..
_bar           : Two..
"""

```

However, when I uncomment the `__baz` entry in the `display` array, I get an exception thrown:

```
DebugInfo:
foo            : One..
_bar           : Two..
Traceback (most recent call last):
  File "getattr.py", line 18, in <module>
    TheClass().getDetails()
  File "getattr.py", line 16, in getDetails
    print '{0:<15}: {1:<20}'.format(key, self.__dict__[ key ] or 'N/A')
KeyError: '__baz'

```

I tried to change how the property was referenced, switching out the `self.__dict__[ key ]` with `getattr( self, key )`, but that just resulted in the same error:

```
DebugInfo:
foo            : One..
_bar           : Two..
Traceback (most recent call last):
  File "getattr.py", line 18, in <module>
    TheClass().getDetails()
  File "getattr.py", line 16, in getDetails
    print '{0:<15}: {1:<20}'.format( key, getattr( self, key ) or 'N/A')
AttributeError: 'TheClass' object has no attribute '__baz'

```

If I just hardcode the properties, then obviously that will work fine:

```py
class TheClass(object):
    def __init__( self ):
        self.foo   = 'One..'
        self._bar  = 'Two..'
        self.__baz = 'Three..'

    def getDetails( self ):
        print "DebugInfo:"
        print '{0:<15}: {1:<20}'.format( 'foo', self.foo or 'N/A')
        print '{0:<15}: {1:<20}'.format( '_bar', self._bar or 'N/A')
        print '{0:<15}: {1:<20}'.format( '__baz', self.__baz or 'N/A')

TheClass().getDetails()

""" Output:
DebugInfo:
foo            : One..
_bar           : Two..
__baz          : Three..
"""

```

But I need this to be a bit more dynamic. So does anyone know if a way to get this working?

Thanks!

**P.S.** I'm using **Python 2.7.11**