[Python-Dev] Alternate notation for global variable assignments

Guido van Rossum guido at python.org
Tue Oct 28 10:36:23 EST 2003

> Why not just:
> import whatevermynameis
> whatevermynameis.foo = bar
> This would be even *more* maximally obvious, as you wouldn't need to
> know what '__me__' means.  :) And how often do you write a module
> without knowing what its name is, or change the name after you've
> written it?  Plus, thanks to the time machine, it already works.  :)

Doesn't work when your module may either be called __main__ or
rumpelstiltkin.  It would then become

  if __name__ == "__main__":
      import __main__ as me
      import rumpelstiltkin as me

which loses the "aha!" effect of a cool solution.  It also IMO
requires too much explanation to the unsuspecting reader who doesn't
understand right away *why* rumpelstiltkin imports itself.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list