开发者

In python beyond 'exec string' is there a way to 'import' using the db as a filesystem

开发者 https://www.devze.com 2022-12-29 15:04 出处:网络
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\'

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

精彩评论

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

关注公众号