I have an executable file, named, for example, resource.py
. It is disposed in the folder named resource
. Renaming file or folder is objectionable - it is old product and users accustomed to use such naming. At old version it was under another project, so imports to it sound like import main_product.resource.<..>
.
Now I need to use imports like import resource.<..>
and __import__('resource.<..>', ...)
. Then I try it, I get an expected error, because Python try to import from the file resource.py
first.
Suggestion solutions:
- remove path of current folder from
sys.path
:- we need an ugly chunk of code at the begin of the file;
- no relative imports will be available in this folder;
- put folder path at the end
sys.path
list:- bigger chunk of ugly code at the begin of the file;
- i am not sure that this feature will always work perfect.
Have any usable idea about this?
P.S. Python v2.6, FreeBSD 7.3