Message163535
As a native speaker, I agree that the sentence, in isolation, is hardly comprehensible. The previous one is also a bit flakey.
The situation is that top-level code executes in a module named __main__, which has one joint global/local namespace that is the global namespace for all subsidiary contexts. '__main__':<__main__ module> is added to sys.modules before user code is executed. The name __main__ is not normally in the __main__ (global) namespace, hence the comment about 'anonymous' in the first sentence. (It is not anonymous in sys.modules.) However (1) __main__ or any other module/namespace can 'import __main__' and get the reference to __main__ from sys.modules and (2) __main__ does have name __name__ bound to the *string* '__main__'. Hence a module can discover whether or not it *is* the __main__ module.
Part of the quoting confusion is that unquoted names in code become strings in namespace dicts, and hence quoted literals when referring to them as keys. What I did not realize until just now is that the __name__ attribute of a module *is* its name (key) in the module namespace (sys.modules dict). For instance, after 'import x.y' or 'from x import y', x.y.__name__ or y.__name is 'x.y' and that is its name (key) in sys.modules. So it appears that the __name__ of a package (sub)module is never just the filename (which I expected), and "__name__ is the module name" only if one considers the package name as part of the module name (which I did not).
The only non-capi reference to module.__name__ in the index is
3.2. The standard type hierarchy
Modules
"__name__ is the module’s name"
But what is the modules name? Its name in sys.modules, which is either __main__ or the full dotted name for modules in packages (as I just learned). Perhaps this could be explained better here. |
|
Date |
User |
Action |
Args |
2012-06-23 06:48:10 | terry.reedy | set | recipients:
+ terry.reedy, loewis, techtonik, ezio.melotti, r.david.murray, docs@python, hynek |
2012-06-23 06:48:08 | terry.reedy | set | messageid: <1340434088.79.0.936099493953.issue15104@psf.upfronthosting.co.za> |
2012-06-23 06:48:07 | terry.reedy | link | issue15104 messages |
2012-06-23 06:48:05 | terry.reedy | create | |
|