Knockout: import modules from the web
Foreword
If you're thinking something along the lines...
"Loading program code from the Internet? This must be the best idea ever" --skulgnome on reddit
... you are right. This code is not safe, and NOT FOR PRODUCTION. But, if nothing else, it shows the power of Python's import hooks.
Basic usage
>>> from knockout import urlimport >>> urlimport.register() Url importing enabled. Add urls to sys.path. A valid url looks like this: http://example.com/path/to/repository/#packagename This stuff is experimental, use at your own risk. Enjoy. >>> import sys >>> sys.path.insert(0, 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/#BeautifulSoup') >>> import BeautifulSoup ... >>> BeautifulSoup <module 'BeautifulSoup' from 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/BeautifulSoup.py'>
Logging
>>> # set logging level to INFO >>> from knockout import urlimport >>> import logging >>> urlimport.log.setLevel(logging.INFO)
How it works
Import hooks. See PEP 302.Download
github
2010-11-20 13:17 | comments