Emulating namespaces in Python
<p>I understand that Python has what it calls "namespaces", but I'm looking to write some code along the lines of <code>security.crypto.hash.md5("b")</code> and such. JavaScript doesn't have namespaces, but their behavior can be replicated using object notation:</p>

<pre><code>var stdlib = {
    math: {
        constants: {
            e: 2.718281828,
            pi: 3.141596535,
            silver: 2.414213562
        },
        operations: {
            add: function(a, b) {
                return a + b;
            },
            subtract: function(a, b) {
                return a - b;
            },
            multiply: function(a, b) {
                return a * b;
            },
            divide: function(a, b) {
                return a / b;
            }
        },
        abs: function(a) {
            if (a &lt; 0) {
                return 0 - a;
            } else {
                return a;
            }
        },
        sgn: function(a) {
            if (a &gt; 0) {
                return 1;
            } else if (a &lt; 0) {
                return -1;
            } else {
                return 0;
            }
        }
    }
}
</code></pre>

<p>This allows for writing code like:</p>

<pre><code>var i = 0;
var j = 1;
var n = stdlib.math.operations.add(i, j);
var constants = Object.create(stdlib.math.constants);
var ops = Object.create(stdlib.math.operations);
var z = ops.multiply(n, constants.e);
</code></pre>

<p>In Python, modules are separated into namespaces by placing them in folders, so <code>os</code> and <code>os.path</code> represent $ROOT/os<code>and ``$ROOT/os/path</code>, respectively. Is there a way to avoid that and do something that emulates namespaces like the above trick with JavaScript?</p>

<p>If all you're after is the dot notation, you can always create classes? See <a href="http://stackoverflow.com/questions/3576596/is-it-a-good-idea-to-using-class-as-a-namespace-in-python">Is it a good idea to using class as a namespace in Python</a>.</p>

python namespaces