This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Arfrever
Recipients Arfrever, docs@python
Date 2011-09-25.20:49:57
SpamBayes Score 2.3836628e-09
Marked as misclassified No
Message-id <1316983798.48.0.694425302693.issue13047@psf.upfronthosting.co.za>
In-reply-to
Content
It's undocumented that imp.find_module("") and imp.find_module(".") try to find __init__.py.

There is also a small difference in behavior between them.
sys.path by default contains "" as the first element, which is sufficient for imp.find_module("."), but not for imp.find_module(""):

$ mkdir /tmp/imp_tests
$ cd /tmp/imp_tests
$ touch __init__.py
$ python3.3 -c 'import imp, sys; print(repr(sys.path[0])); print(imp.find_module("."))'
''
(None, '.', ('', '', 5))
$ python3.3 -c 'import imp, sys; print(repr(sys.path[0])); print(imp.find_module(""))'
''
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named ''

If sys.path contains path (e.g. "." or absolute path) to directory with __init__.py file, then imp.find_module("") will succeed:

$ PYTHONPATH="." python3.3 -c 'import imp, sys; print(repr(sys.path[0:2])); print(imp.find_module("."))'
['', '/tmp/imp_tests']
(None, '.', ('', '', 5))
$ PYTHONPATH="." python3.3 -c 'import imp, sys; print(repr(sys.path[0:2])); print(imp.find_module(""))'
['', '/tmp/imp_tests']
(None, '/tmp/imp_tests/', ('', '', 5))
$ python3.3 -c 'import imp, sys; sys.path.insert(1, "."); print(repr(sys.path[0:2])); print(imp.find_module("."))'
['', '.']
(None, '.', ('', '', 5))
$ python3.3 -c 'import imp, sys; sys.path.insert(1, "."); print(repr(sys.path[0:2])); print(imp.find_module(""))'
['', '.']
(None, './', ('', '', 5))

I think that imp.find_module(".") and imp.find_module("") should have the same behavior, and this behavior should be documented.
History
Date User Action Args
2011-09-25 20:49:58Arfreversetrecipients: + Arfrever, docs@python
2011-09-25 20:49:58Arfreversetmessageid: <1316983798.48.0.694425302693.issue13047@psf.upfronthosting.co.za>
2011-09-25 20:49:57Arfreverlinkissue13047 messages
2011-09-25 20:49:57Arfrevercreate