Title: imp.find_module doc ambiguity
Type: Stage:
Components: Documentation Versions:
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amcnabb, georg.brandl, jimjjewett
Priority: normal Keywords:

Created on 2007-04-26 19:18 by amcnabb, last changed 2007-09-07 07:40 by georg.brandl. 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.
Date User Action Args
2007-09-07 07:40:49georg.brandlsetstatus: pending -> closed
2007-08-23 21:23:49georg.brandlsetstatus: open -> pending
nosy: + georg.brandl
messages: + msg55218
2007-04-26 19:18:44amcnabbcreate