On Tue, Dec 31, 2013 at 10:53 PM, Steven D'Aprano <st...@pearwood.info> wrote: > > __builtins__ with-an-s is a crappy hack that has never worked correctly > and has caused more confusion than help: > > https://mail.python.org/pipermail/python-3000/2007-March/006170.html > > "Restricted mode" in CPython has never worked correctly, __builtins__ > has always been an implementation-specific detail, and you should never > use it. The one you actually want is "__builtin__" (no "s") in Python 2, > or "builtins" (no underscores) in Python 3.
But I didn't say to use the "__builtins__" module. __builtin__ works in Jython, but the module I referenced was "builtins", per the 3.x example given by Denis. I'm definitely not talking about the weird hack that __builtins__ is a module in __main__ in CPython. I've never understood the reason for that, and I loathe it. In every other module it's a dict: >>> d = {} >>> exec("x = 1", d) >>> type(d['__builtins__']) <class 'dict'> I'm not familiar with the implementation of Jython's builtins namespace. Using the name __builtins__ was based on CPython. Just to be clear, I'm talking about the builtins namespace and scope -- however it's implemented in Jython or IronPython. I don't use them and never plan to, so I'm grateful for the correction, Steven. >> But the __builtins__ namespace can and does include names for >> non-built-in objects (e.g. help and exit). > > Only when running interactively, and only when site.py runs. If you > remove or disable site.py, the help and exit functions don't get added. I'm aware of that, and have even mentioned it at least twice in the past. >> The important point in this >> context is that iter is in the builtins module, not that it's a >> built-in function. There are lots of built-in objects that aren't in >> builtins. > > > I'm afraid I've lost the context, and don't understand why this is > important. It's true that not all built-in objects are in builtins, and > not all objects in builtins are built-in, but other than for pedantic > correctness, why does this matter? Denis said: > "iter" is also the name of a builtin function, like "print" My point was that the issue with iter is a namespace issue. It doesn't matter that it's a built-in function like "print". Denis could have meant that either way, so I thought it important to clarify. Why? A while back there was a thread on the list confusing "built-in" functions/methods in the io module and the builtins namespace, and there was even an erroneous bug report filed on a doc string. https://mail.python.org/pipermail/tutor/2013-June/096218.html http://bugs.python.org/issue18249 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor