derived / base class name conflicts

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Nov 13 02:16:05 CET 2005


christopherlmarshall at yahoo.com a écrit :
> Your suggestion ('_name' -> implementation, 'name' -> API) 

This is not "my" convention, it's *the* (mostly agreed upon) Python 
convention. Like 'self', or CONSTANT, or a whole lot of things in Python.

> makes sense
> as a convention between programmers that know a fair amount about each
> other's classes before using them.

No need to know much. dir(modulename.ClassName) is enough.

> I don't think it is reasonable in general to only subclass from base
> classes you have studied the full API of, however. 

Depends on your definition of "studying the full API" !-)

Now if your fear is to accidentally override something in the base 
class, it's just a matter of:
print "API:"
print [name for name in dir(modulename.ClassName) \
        if not name.startswith('_')]

print "IMPLEMENTATION:"
print [name for name in dir(modulename.ClassName) \
        if not name.startswith('_')]

> The double
> underscore is a decent solution to my problem.

Possibly. It can also become a PITA. But it's you who know what your 
code need !-)

> I imagine  it must be used a lot in domains where people are making
> heavy use of third party python code.

I almost never used it (perhaps half-a-dozen times, and only in 
frameworks abstract base classes), and rarely saw it in 3rd part source 
code.



More information about the Python-list mailing list