In python beyond 'exec string' is there a way to 'import' using the db as a filesystem
Although it does not seem possible, I wanted to put this out there to see if others had some innovative solutions to 'dynamically loading and executing code in python'
So if one saved code in a database, one could read it and 'exec it', however if one wanted to use it in a similar fashion to the filesystem, on开发者_开发知识库e would need to
- 'save and load the compiled .pyc'
- create an 'import dbimp' ala 'import imp' etc.
any pointers? ideas? thoughts?
See PEP 302: New Import Hooks, for details on how to hook the importer.
Python 3.1 has an importlib, designed to make hooking the importer a bit easier.
It is possible to implement customized import hooks and register them into sys.meta_path
. See PEP 302 for the details.
精彩评论