随笔分类 - Python
记录学习和使用python中遇到的问题
摘要:###Python和Excel交互使用的python包为XlsxWriter下载的链接[https://pypi.python.org/pypi/XlsxWriter](https://pypi.python.org/pypi/XlsxWriter)初级的例子:```pythondef write_...
阅读全文
摘要:使用setup.cfg和setup.py进行管理1、setup.py文件内容# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDITimport setuptoolssetuptools.setup( setup_...
阅读全文
摘要:来自HeroKu的HTTP API 设计指南http://get.jobdeer.com/343.gethttps://github.com/interagent/http-api-designhttp://blog.fulin.org/2013/10/new_open_api_design.htm...
阅读全文
摘要:1、使用信号量实现函数的超时功能from functools import wrapsimport errnoimport osimport signalimport timeclass TimeoutError(Exception): passdef timeout(seconds=10, ...
阅读全文
摘要:[参考资料]http://www.01happy.com/python-fork-create-process/http://www.python-course.eu/forking.phphttp://stackoverflow.com/questions/10684180/python-chec...
阅读全文
摘要:http://scotdoyle.com/python-epoll-howto.htmlLine 1: The select module contains the epoll functionality.Line 13: Since sockets are blocking by default,...
阅读全文
摘要:https://pythonhosted.org/an_example_pypi_project/setuptools.htmlhttp://www.ianbicking.org/docs/setuptools-presentation/http://lingxiankong.github.io/b...
阅读全文
摘要:[A simple unix/linux daemon in Python](http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/)
阅读全文
摘要:静态方法(staticmethod)类方法(classmethod)静态方法和类方法都可以通过类名.方法名或者实例.方法访问。#-*- coding:utf8 -*- ...
阅读全文
摘要:1、规则要求https://www.python.org/dev/peps/pep-00082、工具https://github.com/jcrocholl/pep83、基本使用方法测试自己的代码:[guosong@etch171 mars171 guosong]# pep8 --first cou...
阅读全文
摘要:在python 下面一个包含中文字符串的列表(list)或字典,直接使用print会出现以下的结果:>>> adict={'a':'中文'} >>> print adict{'a': '\xe4\xb8\xad\xe6\x96\x87'} 在输出处理好的数据结构的时候很不方便,需要使用以下方法进行...
阅读全文
摘要:【背景】在看flower的时候看到__main__.py文件,不知道具体做什么用?故先进行测试看看。【测试代码】测试代码目录结构如下:.`-- test |-- __init__.py |-- __main__.py |-- dep.py__init__.py为空,表示test是一...
阅读全文
摘要:1、背景查看flower的源码,首先看到flower的主程序如下:#!/usr/local/sinasrv2/bin/python2.7# EASY-INSTALL-ENTRY-SCRIPT: 'flower==0.7.3','console_scripts','flower'__requires_...
阅读全文
摘要:1、以HOME目录为准,进行跳转sys.path.append(os.path.dirname(__file__) + os.sep + '../')from config import swordfishconffrom utils import logfrom utils.mysql_base...
阅读全文
摘要:1、原理2、安装mod_wsgihttp://pan.baidu.com/s/1sjsccWHconfigure的时候会找对应的python脚本,默认是/usr/bin/python生成mod_wsgi.so,拷贝到apache的modules下面3、apache的配置:LoadModule wsg...
阅读全文
摘要:https://github.com/tornadoweb/tornado/wiki/Links
阅读全文
摘要:1、https://blog.lzhaohao.info/archive/build-a-comet-application-using-tornado-and-nginx/2、http://qinxuye.me/article/ways-to-continual-sync-browser-and-...
阅读全文
摘要:concurrent.futuresconcurrent.futures提供高层次的接口,用来实现异步调用。这个异步执行可以使用threads(ThreadPoolExecutor)或者process(ProcessPoolExecutor)这个feautre是Python3.2后的新功能,但是也支...
阅读全文
摘要:【优化tornado阻塞任务的三个选择】1、优化阻塞的任务,使其执行时间更快。经常由于是一个DB的慢查询,或者复杂的上层模板导致的,这个时候首要的是加速这些任务,而不是优化复杂的webserver。可以提升99%的效率。2、开启一个单独的线程或者进程执行耗时任务。这意味着对于IOLoop来说,可以开...
阅读全文
摘要:在python中有两种默认的字符串:str和unicode。在Python中一定要注意区分“Unicode字符串”和"Unicode对象”的区别。 后面所有的“Unicode字符串”都是指"Unicode对象”。 一个传统的字符串完全可以用str对象表示,它仅仅是一个字节流,除非解码为unicode对象,否则没有任何实际意义。 一开始先上例子 >>> s='哈哈'>>> s'\xe5\x93\x8...
阅读全文