开发者

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

  1. 'save and load the compiled .pyc'
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜