, , .
, . , alt os, main
print(alt.os.getcwd())
, , os . import os main. , .
, , sys.modules, . sys.modules .
import alt , sys.modules['alt'], alt main. import os alt . , sys.modules['os'] alt.os. import alt import os main, . os , sys.modules['os'].
main getcwd:
():
import alt
import os
print(os.getcwd())
alt ( /):
import alt
print(alt.os.getcwd())
sys.modules ( , , ):
import alt
import sys
print(sys.modules['os'].getcwd())
All imports download the complete module. This also applies to importing a form from os import getcwd. The module sys.modules['os']is still being created. The only difference is that the import namespace will only have access to the name getcwd, not os. In your case, if it altcontains from os import getcwdinstead import os, the three access methods will change as follows:
- Without changes.
print(alt.getcwd())since it alt.osno longer exists.- Without changes.
source
share