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.

classification
Title: Better way to pass objects between imp.find_module() and imp.load_module()
Type: Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Joe.Borg, brett.cannon, ezio.melotti, r.david.murray
Priority: normal Keywords:

Created on 2013-02-28 16:53 by Joe.Borg, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg183220 - (view) Author: Joe Borg (Joe.Borg) Date: 2013-02-28 16:53
If I want to use imp to find some load modules, I have to do it in quite an "unpythonic" way:

>>> name = "os"
>>> file, pathname, description = imp.find_module(name)
>>> imp.load_module(name, file, pathname, description)

Can there not be a better way to pass the tuple (or other object) between find_module() and load_module()?

I'm happy to patch this myself and submit, if it's not already been thought about.
msg183221 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-28 16:56
Does importlib in Python3 provide what you need?  (New features such as this cannot be added to Python2.)
msg183222 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-28 16:58
imp e imp.find/load_module() are also deprecated (or will be deprecated soon).
msg183223 - (view) Author: Joe Borg (Joe.Borg) Date: 2013-02-28 17:02
Thanks for the swift feedback guys, if this is deprecated (i.e. not being carried to Python 3) then close the bug; I'll look at `importlib` and see if it carries the same problem.
msg183225 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-02-28 17:58
Both imp.find_module() and load_module() have been documented as deprecated since Python 3.3. I have not added the warning as I have to work through the stdlib first to remove all current uses.

But for what you are after, Joe, just use importlib.import_module() (which is available in Python 2.7 in the stdlib and earlier on PyPI).
msg183226 - (view) Author: Joe Borg (Joe.Borg) Date: 2013-02-28 18:07
Hi Brett, I missed the fact that it's deprecated as it's not mentioned in the 2.* docs http://docs.python.org/2/library/imp.html.

I can see it is in the 3.*.

Thanks for the feedback.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61523
2013-02-28 18:07:28Joe.Borgsetmessages: + msg183226
2013-02-28 17:58:14brett.cannonsetstatus: open -> closed
resolution: wont fix
messages: + msg183225
2013-02-28 17:02:05Joe.Borgsettype: behavior ->
messages: + msg183223
2013-02-28 16:58:53ezio.melottisetnosy: + brett.cannon, ezio.melotti
type: behavior
messages: + msg183222
2013-02-28 16:56:22r.david.murraysetnosy: + r.david.murray
messages: + msg183221
2013-02-28 16:53:20Joe.Borgcreate