Why is import a Python keyword?
akaptur.github.io
akaptur.github.io
I agree.
A stronger pro-aesthetic example might be:
>>> from xml.sax.saxutils import escape -vs-
>>> escape = __import__("xml.sax.saxutils").sax.saxutils.escape
As another aesthetic, this is much more complicated with __import__: >>> from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
and requires an intermediate variable to reduce import resolution overhead.(That example is from itertools/__init__.py . The ctypes/__init__.py also has a similarly complicated import-as .)
Ignoring this detail, "import" could be simply a function, like "print" and "exec" in Python 3. And with lazy evaluation, even statements could be made into function calls: "if(True, 42, 1/0)" would evaluate to 42 without causing a ZeroDivisionError. The same can be done for assignment: "locals().__setitem__('x', 3)" instead of "x = 3". Keep this up and programs might start to look like this:
define('fac', ('x',), product(range(1, x+1)))
Which is basically a copy of Lisp: (defun fac (x) (product (range 1 (+ 1 x))))