Created
August 15, 2017 20:09
-
-
Save pbfy0/254509d7fb2c98ea7dd81eefb5354957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
def m(): | |
import builtins | |
import importlib | |
import atexit | |
import sys | |
from collections import OrderedDict | |
_imp = builtins.__import__ | |
imports = OrderedDict() | |
def imp(name, globals=None, locals=None, fromlist=(), level=0): | |
imports[name] = True | |
return _imp(name, globals, locals, fromlist, level) | |
@atexit.register | |
def pr(): | |
for i in imports: | |
print(i) | |
builtins.__import__ = imp | |
m() | |
del m | |
if __name__ == '__main__': | |
print(sys.path) | |
sys.argv.pop(0) | |
fil = sys.argv[0] | |
sys.path[0] = os.path.dirname(fil) | |
print(sys.path) | |
with open(fil, 'r') as f: | |
code = compile(f.read(), fil, 'exec') | |
exec(code, globals(), locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment