友链
导航
These are the good times in your life,
so put on a smile and it'll be alright
友链
导航
Wraps pip and virtualenv to install scripts
sudo pip install pipsi
# 安装 pip $ sudo apt-get install python-pip # 安装模块 (python 不像 node.js 会从本项目目录加载模块, # 而是将模块统一装在系统盘 所以要 sudo) # /usr/local/lib/python2.7/dist-packages/ $ sudo pip install Flask # 手动安装 pip 的包的办法 # 1. 下载, 如 https://pypi.python.org/pypi/mosquitto/1.2.3 # 2. tar zxf ... # 3. cd && sudo python setup.py install
# 建立一个项目 $ mkdir schedulingapp $ cd schedulingapp/ # 在这个项目中安装 python2.7 的独立环境 $ virtualenv venv --python=python2.7 # 进入 venv $ . venv/bin/activate # 进入后, 会在提示符前显示 (venv) (venv)$ # 安装模块 (venv)$ pip install flask # 可确认是安装到了 venv 中 (venv)$ find venv/ -name flask venv/lib/python2.7/site-packages/flask # 退出 venv 没有直接方法, 重开 terminal 吧
Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块。 Pexpect 的使用范围很广,可以用来实现与 ssh、ftp 、telnet 等程序的自动交互;可以用来自动复制软件安装包并在不同机器自动安装;还可以用来实现软件测试中与命令行交互的自动化。
from flask import Flask # The argument tells Flask where to find application static assets and # templates. __name__ informs Flask to use the current module to # location resources. app = Flask(__name__) # defined a couple of routes @app.route('/', defaults={'name':"Guest"}) @app.route('/<string:name>' , methods=['GET']) def say_hello(name): return "Hehe " + name if __name__ == "__main__": app.run(debug=True)
Tornado is an open-source Python Web framework and non blocking web server. It has excellent scalability characteristics due to its non-blocking network I/O nature and scales to thousands of simultaneous connections.
但从例程上看是顺序的, 并无回调, 不清楚 non-blocking 只是接受网络请求时有还是怎么回事.
另外, 还有个 web.py, 据说是类似 tornado 是异步的. 但由于是 Aaron_Swartz 写的, 现在已经是历史了.
TextBlob is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.
TextBlob是一个用Python编写的开源的文本处理库。它可以用来执行很多自然语言处理的任务,比如,词性标注,名词性成分提取,情感分析,文本翻译,等等。
TextBlob 依赖 python 的 NLTK | Natural Language Toolkit 和 Pattern | a web mining module 库.
# flask 下 @app.route('/api/v1/sentiment/<message>') def sentiment(message): text = TextBlob(message) response = {'polarity' : text.polarity , 'subjectivity' : text.subjectivity} return jsonify(response)
goose-extractor : Python Package Index
pip install goose-extractor
# flask 下 @app.route('/api/v1/extract') def extract(): url = request.args.get('url') g = Goose() article = g.extract(url=url) response = {'title' : article.title , 'text' : article.cleaned_text[:250],'image': article.top_image.src} return jsonify(response)
09 年 arc90 Readability 还是个开源项目, 11 年就已经是个商业产品 Readability.com 了.
github 上可以找到原始 readability 的 python/node.js 等实现.
readability.com 也提供 API.