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 brett.cannon
Recipients berdario, brett.cannon, eric.snow, ezio.melotti, ncoghlan
Date 2014-01-21.16:57:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1390323445.16.0.852298569371.issue20321@psf.upfronthosting.co.za>
In-reply-to
Content
It actually is a caching issue, but not with the caches in the finder but the cache *of* finders. Because you inserted LIBDIR before it existed, import noticed it didn't exist and so put None into sys.path_importer_cache[LIBDIR] (or imp.NullImporter prior to Python 3.3). If you del sys.path_importer_cache[LIBDIR] just before trying to import impfile then it works. If you leave the directory around but clear out its contents then importlib.invalidate_caches() would have been needed.

As you have noticed, dynamically mucking around import is rather delicate. There are various caches and tricks used in order to speed it up since it is such a common operation. If you are trying to just load a single file that you dynamically wrote you can load the file directly using http://docs.python.org/3/library/importlib.html#importlib.machinery.SourceFileLoader (or if you need to support Python 2.7 as well, http://docs.python.org/2.7/library/imp.html#imp.load_module).

Do let me know if you are trying to just load a single file. I'm contemplating adding a utility function to help with that use-case in importlib.
History
Date User Action Args
2014-01-21 16:57:25brett.cannonsetrecipients: + brett.cannon, ncoghlan, ezio.melotti, eric.snow, berdario
2014-01-21 16:57:25brett.cannonsetmessageid: <1390323445.16.0.852298569371.issue20321@psf.upfronthosting.co.za>
2014-01-21 16:57:25brett.cannonlinkissue20321 messages
2014-01-21 16:57:24brett.cannoncreate