Juergen wrote: > I had a problem yesterday where I wanted to extend a top-level module > by a module in a subpackage. I naively named my module the same as the > toplevel module, and peer import bit me. I finally had to rename my > module for no good reason to get things working. What you are trying to do seems likely to cause confusion. But if you really need this, couldn't you just mangle sys.path for a single import and then restore it? It's kind of ugly but it would work. > So my question is: is there an easy way to force a top-level import > (adress the top-level namespace), that I overlooked? > > If not, what do you think of a > > from __top__ import systemmodule > > similar to from __future__ ... I don't like this idea. I'd hate to encourage people to give their subpackages the same name as system modules: from package import string # many lines of code later string.do_something_wierd() # what?!? > An alternative syntax would be "import .systemmodule", but that seems > obscure. That's grotesque. Especially since I think of a leading period as meaning current directory :-) Cheers, Brian
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