Issue 1708326: imp.find_module doc ambiguity (original) (raw)

Created on 2007-04-26 19:18 by amcnabb, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31901 - (view) Author: Andrew McNabb (amcnabb) Date: 2007-04-26 19:18
The doc string for find_module doesn't make it clear that you can do: stats_path = imp.find_module('scipy/stats') It makes it sound like you would have to do: scipy_path = imp.find_module('scipy')[1] stats_path = imp.find_module('scipy', stats_path)[1] However, the shorter snippet seems to work just fine.
msg31902 - (view) Author: Jim Jewett (jimjjewett) Date: 2007-05-01 13:48
Are you sure it works the same? I would expect that (1) The longer form first finds a module (or package) named scipy, then finds the (sub-)module stats within it. The shortcut form might not provide enough of the scipy context. (Whether this actually matters probably depends on what stats does, how much it depends on the rest of scipy, and what you need it for.) (2) The longer form would work using python abstractions, while the short form would depend on how files happened to be stored on your machine. Your storage format is fairly common, but not guaranteed. For example, would the short form work on windows, where directory slashes (sometimes) need to go the other direction? Would it work if scipy were in a zipfile egg?
msg31903 - (view) Author: Andrew McNabb (amcnabb) Date: 2007-05-01 18:57
Given the issues you brought up, I guess I'm surprised that the shortcut form is accepted, since it seems that it would often do the wrong thing.
msg55218 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-23 21:23
IMO it is your responsibility to make sure that the module name you pass is a valid Python module name.
History
Date User Action Args
2022-04-11 14:56:24 admin set github: 44903
2007-09-07 07:40:49 georg.brandl set status: pending -> closed
2007-08-23 21:23:49 georg.brandl set status: open -> pendingnosy: + georg.brandlmessages: +
2007-04-26 19🔞44 amcnabb create