Question: Recently, I find myself writing code like this:

```

for name in dir( object ):
    if name.startswith( '__' ) : continue
    ...

```

Is there a more pythonic way to access the object's "public" namespace?

Answer: 
You could use the [`vars` function](http://docs.python.org/library/functions.html#vars) instead.

For example:

```
>>> class C(object):
...   def __init__(self):
...     self.__foo = 'foo'
... 
>>> c = C()
>>> dir(c)
['_C__foo', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__',    
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',    
'__weakref__']
>>> vars(c)
{'_C__foo': 'foo'}

```

Note that, as Niklas R has pointed out, variables with a single underscore are also considered private. However the `vars()` function has the advantage of eliminating all but the instance variables.
Rather than an exclusion branch using the `continue` keyword, iterating over a comprehension of public names directly seems more Pythonic. But it could just be a matter of taste, it's admittedly not much better than what you already have.

```
public_names = (n for n in dir(object) if not n.startswith('_'))
for attr in public_names:
    ...

```

*Note:* Single underscore attributes are also not "public".