[Python-Dev] bug or feature in imp.load_module()?

Neal Norwitz neal@metaslash.com
Wed, 17 Oct 2001 14:22:43 -0400


Guido van Rossum wrote:
> 
> > module = imp.load_module(path, file, filename, smt)
> >
> > After returning from imp.load_module(), the file paramter passed in
> > may be at the beginning or end depending on whether it was byte
> > compiled.  If the file was already compiled, the file returned will
> > stay at the beginning.  If the file was byte compiled in
> > load_module(), the file will be at the end.
> 
> This certainly doesn't surprise me -- in one case it read the source
> and in the other case it didn't read the source.
> 
> If you pass a file to a function, I don't think that there is any
> guarantee to the file position when it returns, so I don't think this
> should be documented.  I can't think of why you'd expect it to be at
> any specific position.

I'm not sure either. :-)  It was odd for me to pass both file & filename.
The doc says that:

	The file argument is an open file, and filename is 
	the corresponding file name; these can be None and '', 
	respectively, when the module is not being loaded from a file.

I'm not sure how the module could not be loaded from a file (unless
the implication is that the file argument is None and a new file will
be opened from the filename).

If the file can be None anytime, it makes more sense to me.
But the last phrase in the doc seems to indicate the file argument
should not be None.

Perhaps, it's just me, it wouldn't be the first time. :-)

Neal