ok, well, this is a python list so let's not turn this into a C++
discussion. However, the above link contains a couple of wrong
statements. To get this back on track, only this:
class nesting uses the fact that a class (in C++) acts as an ordinary
scope, so you can use it the same way as a namespace, to bind names
to a common scope, and avoid name clashes if the name you want to define
is general, but has a specific meaning in the scope within which you want
to use it. ('Geometry::Point' for example).
Back to my python code:
I tried to mirror the structure of a package I provide ('Synopsis') in
a Config class. Since the synopsis tool is very modular, each submodule
contains its own set of parameters which you might want to configure.
Passing all of them as command line options will quickly get very messy,
so we figured we might just provide the possibility to write a config
script that sets all the flags/options at the right scope. For example:
Some options apply to more than one module, so it appears natural to
define it in an 'outer scope'. This, however, assumes that 'inner scopes'
(aka nested classes) can see the variables defined in outer scopes.
I hope this somewhat explains what I'm aiming at...
But my head still spins when I try to think of a C++ class that
hasn't been instantiated.
Again, we are talking about classes as scopes, not class instances.
self.prefix = 'usr/local'
def __init__(self, parent):
self.prefix = os.path.join(parent.prefix, 'share')
You could remember the parent, but that'd lead to a circular
reference (not such a bad thing for 2.x).
right. This gets pretty messy too, as you are forced to use instances,
while I was trying to avoid that. In fact, I could have used modules
instead of classes, but since python constrains me to one module per file,
I tried to get away with something a bit finer grained.
Perhaps if you give us C++ code of what you're trying to do, we
can tell you why you don't need to do it ;)
right. That's exactly what I want. Please show me the right idiom to use
in python to solve the above problem.
And by the way, the project I'm talking about is 'synopsis', athttp://synopsis.sourceforge.net/,
a modular source code inspection tool
with parsers for IDL, C++, python, and a couple of output formatters.
The module structure is this:
and each node in this tree has its own set of parameters.
Online docs are at http://synopsis.sourceforge.net/docs/index.html