I study many answers on similar questions (opening same name modules that is trivial) but I not found answer to this question how to open module with same file name as __main__
program.
Let see my code tree (it is simplified for this purpose):
<source root>
log_parser/
log_parser.py (module to import)
my_system/
log_parser/
log_parser.py (__main__)
As you see on the tree I want to import log_parser/log_parser
. <source root>
is added to path.
Python adds to path current path as first. I found that I can exclude current path from import paths and this works. Is there and alternative solution more pythonic?
<other imports>
sys.path = sys.path[1:]
from log_parser.log_parser import LogParser
How to import without monkey like that sys.path = sys.path[1:]
or del sys.path[0]
?
I can rename modules but I do not want ugly and too long names like my_system_log_parser.my_system_log_parser
.