[Python-ideas] A "within" keyword

David Teresi dkteresi at gmail.com
Fri Jun 8 14:41:54 EDT 2018


One of the features I miss from languages such as C# is namespaces that
work across files - it makes it a lot easier to organize code IMO.

Here's an idea I had - it might not be the best idea, just throwing this
out there: a "within" keyword that lets you execute code inside a
namespace. For example:

# A.py
import types
cool_namespace = types.SimpleNamespace()

within cool_namespace:
    def foo():
        print("foo run")

#B.py
import A
within A.cool_namespace:
    foo() # prints "foo run"

Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180608/d874270a/attachment.html>


More information about the Python-ideas mailing list