Skip to content

Instantly share code, notes, and snippets.

@sprout42
Created September 3, 2022 01:55
Show Gist options
  • Save sprout42/e78654c88b65e4b64ae5ab52bf3b5e64 to your computer and use it in GitHub Desktop.
Save sprout42/e78654c88b65e4b64ae5ab52bf3b5e64 to your computer and use it in GitHub Desktop.
fun with python
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