David Anton wrote:
> Is this an acceptable way to simulate the type of namespace you'd define in
> C#, VB, etc?
>
> class SimulatedNamespace:
> class SomeClass(object):
> ....
>
> It seems to work ok in my tests, but is there some pitfall to doing this?
>
For pure Python code I'd use a module instead of a namespace - but the
syntax isn't as nice.
class SomeClass(object):
pass
import imp
mod = imp.new_module("name")
mod.SomeClass = SomeClass
Your way is fine, if a slightly odd use of the class statement - but a
module is a better match for the namespace concept in Python terms. The
downside of a module is that it will also contain the builtins. The
downside of a class is that it will have some default methods.
Michael Foord
http://www.voidspace.org.uk/python/index.shtml
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com