At 11:50 17.05.2004 -0400, Phillip J. Eby wrote: >At 05:37 PM 5/17/04 +0200, M.-A. Lemburg wrote: >>Samuele Pedroni wrote: >>>At 16:55 17.05.2004 +0200, M.-A. Lemburg wrote: >>>>Are you saying that you are not going to change the default __import__() >>>>implementation, only the way it is called ? (I wonder how you'll >>>>enforce the 'absolute only' strategy then) >>>if you pass globals = {} you get absolute imports from __import__, >> >>Ahh, a hidden feature :-) I didn't know that one yet. > >More of an emergent property. Keep in mind that the current relative >mechanism is always relative *to* something, and that "something" is >defined by the globals['__name__'], if any. If there is no '__name__', >then the import has to be absolute. For example, you would expect this: > > exec "import foo" in {},{} > >to be an absolute import, would you not? yes, and __import__('foo') triggers also an absolute import because the default for globals is a conceptually empty namespace, not the caller globals. Respectively this can trigger a relative import: __import__('foo',globals()) and the relevant bit is indeed __name__ .
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4