Recently, I was asked to move the code from one subpackage to another at work, and the approach I used did not seem immediately obvious to other developers, so I am documenting it here for others.
. script, . .
, , .
:
. CVS, . (, mercurial, subversion git) mv , . git:
git mv /location/old/script.py /location/new/script.py
:
unittests, __init__.py, . , __init__.py ,
, , ,
/location/old/script.py:
from location.new.script import *
, , , . __init__.py, , __init__.py.
. import * __all__. __all__, . :
from location.new.script import *
from location.new.script import foo, bar, baz
__init__.py sys.modules :
from location.new import script
import sys
sys.modules['location.old.script'] = script
sys.modules , . , os.path Python. sys.modules. , , , Python.
, . , , .
: script ( , !), .
:
, , :
(import|from).*location\.old.*script
Unix ( Cygwin), :
grep -rEe "(import|from).*location\.old.*script" .
IDE .
, , , . :
import location.old.script
import location.new.script
from location.old import script
from location.new import script
.
:
. - , , .
: script
. - /, , . , , , .
, , , .
, , , . , .