Skip to content

Instantly share code, notes, and snippets.

@gsnedders
Created November 1, 2016 02:17
Show Gist options
  • Save gsnedders/1208666ce1bf141e07578168aa5b3647 to your computer and use it in GitHub Desktop.
Save gsnedders/1208666ce1bf141e07578168aa5b3647 to your computer and use it in GitHub Desktop.
import sys
class Test(object):
def find_module(self, fullname, path=None):
print('finder looking for %r with path %r' % (fullname, path))
return None
def foo():
sys.meta_path.append(Test())
def bar():
import xml.etree.ElementTree
foo()
bar()
@gsnedders
Copy link
Author

$ python2 test.py 
finder looking for 'xml' with path None
finder looking for 'xml._xmlplus' with path ['/usr/lib/python2.7/xml']
finder looking for '_xmlplus' with path None
finder looking for 'xml.etree' with path ['/usr/lib/python2.7/xml']
finder looking for 'xml.etree.ElementTree' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'xml.etree.sys' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'xml.etree.re' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'xml.etree.warnings' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'xml.etree.ElementPath' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'xml.etree.ElementC14N' with path ['/usr/lib/python2.7/xml/etree']
finder looking for 'ElementC14N' with path None
$ python3 test.py
finder looking for 'org' with path None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment