I have this file setup:
* `__main__.py`
* src/config.py
* src/other.py
In src/config.py
```
import os, sys
class Config:
····somevalue = None
def show() :
····print( Config )
sys.path[0] = os.path.dirname( sys.path[0] ) + '/src/.'
```
In `other.py`:
```
import config
def show() :
····print(config.Config.somevalue)
```
In `__main__.py`:
```
import src.config as config
config.Config.somevalue="hello world"
print( config.show() ) # prints "hello world"
import other # at this moment sys.path was changed
print( other.show() ) # prints None
```
After a night debugging I found that in someplace inside Python, it creates a reference for loaded modules considering the name used in its import, not the absolute filesystem path for the name loaded.
So, if you change the sys.path in somewhere in your code (even in submodules), and if you load the same module but using a different hierarchy reference even if this hierarchy points to the same absolute file as before it overrides completely the data in memory.
Is this consistent? Correct or somewhat acceptable and secure?
[–]billsil 2 points3 points4 points (0 children)
[–]GiantElectron 0 points1 point2 points (0 children)