Just hitting a strange problem with Python import behavior. It is the same on all Python 2.x versions and it is probably correct, but I currently don't understand why this happens. I have created a directory "dir" with the following three module, __init__, hello, and test2; and another module test1 in the parent directory, like that: --- test1.py ---------- from dir import test2 ------------------------ --- dir/__init__.py --- print "init" ----------------------- --- dir/hello.py ------ print "hello world" ----------------------- --- dir/test2.py ------ import sys sys.path = [] import hello ----------------------- The script test2.py removes all entries from the sys.path. So when I run test2.py directly, I get an ImportError because the hello module cannot be imported. This is as expected. However, if I run test1, the hello module *is* imported and I get the "hello world" message. Why is that?? Probably there is a simple explanation, but currently I simply don't get it. -- Christoph
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