
python
文章平均质量分 93
翟海飞
这个作者很懒,什么都没留下…
展开
-
Python守护进程daemon实现
1 守护进程1.1 守护进程守护进程是系统中生存期较长的一种进程,常常在系统引导装入时启动,在系统关闭时终止,没有控制终端,在后台运行。守护进程脱离于终端是为了避免进程在执行过程中的信息在任何终端上显示并且进程也不会被任何终端所产生的终端信息所打断。在这里,我们在Linux2.6内核的centos中,ps -ef |awk '{print $1"\t "$2"\t "$3"原创 2017-04-17 18:10:50 · 21442 阅读 · 0 评论 -
Python并发编程eventlet
1 多进程、多线程和协程python并发编程之多进程、多线程、异步和协程:http://www.cnblogs.com/tyomcat/p/5486827.html1.1 总结1)多进程能够利用多核优势,但是进程间通信比较麻烦,另外,进程数目的增加会使性能下降,进程切换的成本较高。程序流程复杂度相对I/O多路复用要低。2)I/O多路复用是在一个进程内部处理多个逻辑流程,不用进行原创 2017-04-16 17:49:55 · 1447 阅读 · 0 评论 -
Python写入中文到mysql时乱码
1 保证MySQL的输出没有乱码的三步 1 Python文件设置编码 utf-8 (文件前面加上 # coding=utf-8)# -*- coding: UTF-8 -*-参考:http://www.runoob.com/python/python-chinese-encoding.html 2 Python连接MySQL是加上参数 charset=utf8原创 2017-04-16 15:53:02 · 2829 阅读 · 0 评论 -
Python JSON
1 JSONJSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of t原创 2017-03-07 15:39:36 · 574 阅读 · 0 评论 -
MongoDB与Python调用
1 在Ubuntu下安装1.1 安装MongoDB包:# apt-get install mongodb-server mongodb-clients python-pymongo安装完成后,mongod进程后启动:root@ubuntu:~# ps -ef | grep mongomongodb 2122 1 14 16:39 ? 00:00:06 /usr/bin/m原创 2017-03-02 17:22:54 · 1419 阅读 · 0 评论 -
python修改文件内容
1 替换文件中的一行1.1 修改原文件1 要把文件中的一行Server=192.168.22.22中的IP地址替换掉,因此把整行替换。data = ''with open('zhai.conf', 'r+') as f: for line in f.readlines(): if(line.find('Server') == 0): line = 'S原创 2017-03-02 11:15:48 · 45855 阅读 · 2 评论 -
Python数据库连接池DBUtils
1 问题由来前一段时间用Mysqldb模块进行数据库的开发。共用一个数据库连接:import MySQLdb as mdb def create_single_conn(self): self._mysql_connection = mdb.connect( '%s' % conf.db['host'], '%s' % conf原创 2017-01-04 10:57:00 · 41707 阅读 · 3 评论 -
DBUtils User's Guide及中文
DBUtils User's GuideVersion:1.1Released:08/14/11Translations:English GermanContentsSynopsisModulesDownloadInstallationInstallation as a stan原创 2017-01-03 18:30:25 · 2314 阅读 · 0 评论 -
MySQLdb:Python 操作 MySQL 数据库
MySQL for Python:https://sourceforge.net/projects/mysql-python/files/Github: https://github.com/farcepest/MySQLdb1MySQL Python tutorialThis is MySQL Python programming tutorial.原创 2016-12-28 18:55:05 · 4428 阅读 · 0 评论 -
Python查询Mysql, sqlite时返回字典结构的代码
MySQLdbMySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。默认程序: import MySQLdb db = MySQLdb.connect(host = ´localhost´, user = ´root´, passwd = ´123456´, db = ´te原创 2016-12-27 19:14:13 · 8085 阅读 · 0 评论 -
Python——greenlet
Introduction一、介绍 A “greenlet” is a small independent pseudo-thread. Think about it as a small stack of frames; the outermost (bottom) frame is the initial function you called, and the in转载 2016-12-20 17:39:20 · 808 阅读 · 0 评论 -
Pycharm远程连接服务器(windows下远程修改服务器代码)
http://blog.csdn.net/duankaifei/article/details/418986411、写在前面 之前一致用putty,ssh,修改代码,或者本地修改,上传到服务器,各种不爽,现在改用xshell,但是有时候还是不方便感觉,于是自己配置了远程连接pycharm,这样不用总是到代码里修改,直接在windows下pycharm里修改再保存就可以实现同步更新转载 2016-12-16 13:09:24 · 81393 阅读 · 6 评论 -
python去掉字符串中空格的方法
要去掉字符串"{{ banner }}"中的空格,并取出字符串使用如下方法:>>> s = "{{ banner }}">>> ''.join(s.split(' '))[2:-2]'banner'参考:1.strip():把头和尾的空格去掉2.lstrip():把左边的空格去掉3.rstrip():把右边的空格去掉4.replace('c1','c2'原创 2016-07-22 16:29:01 · 1790 阅读 · 0 评论 -
python总结
1 字符串单引号(')你可以用单引号指示字符串,就如同'Quote me on this'这样。所有的空白,即空格和制表符都照原样保留。双引号(")在双引号中的字符串与单引号中的字符串的使用完全相同,例如"What's your name?"。三引号('''或""")利用三引号,你可以指示一个多行的字符串。你可以在三引号中自由的使用单引号和双引号。 自然字符串如果你原创 2016-07-07 23:09:16 · 1996 阅读 · 0 评论 -
Django项目结构布局
每个真正的程序员,可能都会梦想着能够发布开源项目,让自己的代码被别人所用。开源项目会发布到开发的版本管理系统(比如GitHub)上面,为了让大家能够方便使用你的代码,项目的目录结构应该遵循一定的规范。即使不是开源项目,项目目录结构符合一定的规范对你的项目管理也是有好处的。下面列出python开源项目的通常目录结构及说明:.tx/转载 2016-06-27 14:28:24 · 6256 阅读 · 0 评论 -
ubuntu16.04下安装的mysql数据库问题
1 字符集问题问题:在django中执行./manage.py createdb命令后出现:django.db.utils.OperationalError: (1366, "Incorrect string value: '\\xC4\\x9A\\xC2\\x81vi...' for column 'file' at row 1")查看mysql数据库:mysql> show v原创 2016-06-24 09:50:49 · 8672 阅读 · 0 评论 -
最全Pycharm教程
原文:http://blog.csdn.net/u013088062/article/details/50100121 最全Pycharm教程(1)——定制外观 最全Pycharm教程(2)——代码风格 最全Pycharm教程(3)——代码的调试、运行 最全Pycharm教程(4)——有关Python解释器的相关配置 最全Pycharm教程(5转载 2016-06-16 18:58:31 · 5871 阅读 · 0 评论 -
virtualenv和virtualenvwrapper总结
原文:http://colesmith.space/2015/05/19/revise-virtualenv-and-virtualenvwrapper.html官方文档virtualenvvirtualenvwrapper一 virtualenvWhat:virtualenv 是一个隔离Python环境的工具.Why:virtualenv 可以让你转载 2016-06-15 18:11:02 · 4922 阅读 · 0 评论 -
PyCharm中使用virtualenv进行django开发
1 在设置中找到Project Interpreter打开PyCharm,选择file->settings在弹出的窗口搜索,project、interpreter等关键字均可,找到 Project Interpreter2 设置Project Interpreter1. 点击该界面的最右侧的一个锯齿形状的按钮2. 在下拉列表中有个"Create VirtualEn原创 2016-06-15 17:47:53 · 7089 阅读 · 0 评论 -
ubuntu16.04下virtualenv环境中, django与mysql安装
1 安装virtualenvzhai@zhai:~$ pip listThe program 'pip' is currently not installed. You can install it by typing:sudo apt install python-pipzhai@zhai:~$ sudo apt install python-pip...You are原创 2016-06-14 18:56:25 · 5860 阅读 · 0 评论 -
pycharm使用总结
参考:http://www.wtoutiao.com/a/2454799.htmlpycharm常用设置:file -> Setting ->Editor1. 设置Python自动引入包,要先在 >general > autoimport -> python :show popup快捷键:Alt + Enter: 自动添加包2. “代码自动完成”时间延时设置原创 2016-06-13 16:00:14 · 84688 阅读 · 0 评论 -
Bootstrap tutorial: A responsive design tutorial with Twitter Bootstrap 3
原文:http://www.revillweb.com/tutorials/bootstrap-tutorial/IntroductionThis bootstrap tutorial will show you how to create a responsive template using twitter bootstrap 3. We will create a r转载 2016-06-13 15:49:27 · 1581 阅读 · 0 评论 -
Selenium Web Driver
1 WebDriver1 WebDriver介绍Selenium 2.0最主要的新特性就是集成了精心设计的面向对象的WebDriver API。WebDriver提供更加简单明了的接口来弥补Selenium-RCAPI的不足。WebDriver更好的支持动态网页2 WebDriver与Selenium-RC如何驱动浏览器1) 对于所有支持的浏览器Selenium-R原创 2015-09-30 15:43:05 · 1643 阅读 · 0 评论 -
Selenium私房菜系列
在这段期间,我一直在找关于服务器的端测试方案,自动化工具等等,无意间我发现了Selenium这个工具。在试用一段时间后,觉得Selenium确实是一个很不错的Web测试工具。在和强大的QTP比较后,我最后还是选择了使用Selenium,主要的原因是工具使用灵活,简单,并且完全满足我的要求。而QTP虽然强大,但它的使用让我觉得非常繁琐,而调试功能也让我郁闷......鉴于种种这样的原因,我最后选择了转载 2015-09-29 16:13:48 · 787 阅读 · 0 评论 -
Python生态环境简介
Python生态环境简介作者:Mir Nazim原文:Python Ecosystem - An Introduction译者:dccrazyboy 原译:Python生态环境简介当开发人员从PHP,Ruby或者别的开发环境转换到Python时,所面对的最大问题是缺乏对Python开发的生态环境的充分理解。转载 2015-04-01 10:56:00 · 1955 阅读 · 0 评论 -
python汇 安装问题
问题1:Could not find any downloads that satisfy the requirement XStatic-Angular-Irdragndrop>=1.0.2.1 (from horizon==2015.1.dev110)Some externally hosted files were ignored as access to them may原创 2015-04-01 10:41:31 · 1335 阅读 · 0 评论 -
python汇 包管理
1 包管理2 包管理工具相关术语:https://docs.python.org/2/distutils/introduction.htmlhttps://python-packaging-user-guide.readthedocs.org/en/latest/glossary.html2.0 工具使用建议2.0.1 安装1 使用pip从p原创 2015-03-09 18:51:37 · 1519 阅读 · 0 评论 -
关于python中的setup.py
前言其实对于setup.py和setup.cfg的关注是从OpenStack的源码包中开始的,OpenStack每个组件的发布时都是一个tar.gz包,同样,我们直接从github上clone代码后也会发现两个文件的存在。当阅读Nova或Ceilometer(其他组件可能也会涉及)的代码时,发现setup.cfg中内容对于代码的理解有很大的影响。那么,到底setup.py和setup.转载 2015-03-05 18:16:02 · 1258 阅读 · 0 评论 -
使用 Python Mock 类进行单元测试
Data type, model, or node -- these are just some of the roles a mock object might assume. But how does a mock fit inside a unit test setup?Sometimes, you need "other" code resources for your tes转载 2015-03-04 09:30:06 · 3283 阅读 · 0 评论 -
python哲学理念
python哲学理念:Explicit is better than implicit. 简称:EIBTI>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than com原创 2015-01-12 17:13:43 · 2986 阅读 · 0 评论 -
python classmethod staticmethod
cls(value)原创 2015-01-09 17:38:30 · 931 阅读 · 0 评论 -
python with
http://www.ibm.com/developerworks/cn/opensource/os-cn-pythonwith/http://blog.csdn.net/largetalk/article/details/6910277http://jianpx.iteye.com/blog/505469原创 2015-01-08 18:18:04 · 622 阅读 · 0 评论 -
python super()
http://www.cnblogs.com/lovemo1314/archive/2011/05/03/2035005.html一、问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1: 代码段1:class A: def __init__(self): prin转载 2015-01-08 18:02:08 · 674 阅读 · 0 评论