Created
September 3, 2022 01:55
-
-
Save sprout42/e78654c88b65e4b64ae5ab52bf3b5e64 to your computer and use it in GitHub Desktop.
fun with python
This file contains hidden or 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 builtins | |
_old_import = builtins.__import__ | |
def _test_import(*args, **kwargs): | |
print('before!', args, kwargs) | |
# args 2 and 3 are dictionaries that have the namespace in them, remove | |
# evidence of our python crimes | |
for a in args: | |
if isinstance(a, dict) and '_old_import' in a: | |
del a['_old_import'] | |
if isinstance(a, dict) and '_test_import' in a: | |
del a['_test_import'] | |
print('after!', args, kwargs) | |
return _old_import(*args, **kwargs) | |
builtins.__import__ = _test_import | |
import os | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment