name = 'Justin'
import some
print(some.name) # Justin
del some
print(some.name) # NameError: name 'some' is not defined
import some print(some.name) # Justin del some
import some print(some.name) # Justin
>>> import sys >>> sys.modules.keys() dict_keys(['heapq', 'sre_compile', '_collections', 'locale', '_multibytecodec', 'functools', 'encodings', 'site', 'operator', 'io', '__main__', 'copyreg', '_hea pq', '_weakref', 'abc', 'builtins', 'errno', 'itertools', 'sre_constants', 're', 'encodings.latin_1', 'collections', 'ntpath', '_sre', 'nt', 'genericpath', 'sta t', 'zipimport', '_codecs', '_bisect', 'encodings.utf_8', 'sys', 'codecs', 'os.p ath', '_functools', '_locale', 'keyword', 'bisect', '_codecs_tw', 'signal', 'wea kref', '_io', '_weakrefset', 'encodings.cp950', 'encodings.aliases', 'sre_parse' , 'os', '_abcoll']) >>> |
import sys
import some
print(some.name) # Justin
del some
print(sys.modules['some'].name) # Justin
print(some.name) # NameError: name 'some' is not defined
import some as other
print(other.name) # Justin
import some from some import name print(name) # Justin print(some.name) # Justin name = 'caterpillar' print(name) # caterpillar print(some.name) # Justin
list = [1, 2, 3] print(list)
>>> import other [1, 2, 3] >>> from other import list >>> list [1, 2, 3] >>> list[0] = 100 >>> list [100, 2, 3] >>> other.list [100, 2, 3] >>> |