#pythonの誰かが、モジュール「herpaderp」を検索し、検索対象としてリストされているすべてのモジュールを検索することを提案しました。この場合、ImportErrorを発生させる前に、システム上のすべてのモジュールを一覧表示しないのはなぜですか?誰かがここで何が起こっているのかを明らかにすることができますか?
import sys
class TempLoader(object):
def __init__(self, path_entry):
if path_entry == 'test': return
raise ImportError
def find_module(self, fullname, path=None):
print fullname, path
return None
sys.path.insert(0, 'test')
sys.path_hooks.append(TempLoader)
import herpaderp
出力:
16:00:55 $> python wtf.py
herpaderp None
apport None
subprocess None
traceback None
pickle None
struct None
re None
sre_compile None
sre_parse None
sre_constants None
org None
tempfile None
random None
__future__ None
urllib None
string None
socket None
_ssl None
urlparse None
collections None
keyword None
ssl None
textwrap None
base64 None
fnmatch None
glob None
atexit None
xml None
_xmlplus None
copy None
org None
pyexpat None
problem_report None
gzip None
email None
quopri None
uu None
unittest None
ConfigParser None
shutil None
apt None
apt_pkg None
gettext None
locale None
functools None
httplib None
mimetools None
rfc822 None
urllib2 None
hashlib None
_hashlib None
bisect None
Traceback (most recent call last):
File "wtf.py", line 14, in <module>
import herpaderp
ImportError: No module named herpaderp