Python
文章平均质量分 72
chinaren0001
普通真诚的老百姓!
展开
-
使用LDTP+Pywinauto实现主机与虚拟机之间的拖拽(DnD: Drag and drop)自动化测试
主机和虚拟机之间的拖拽是一个常用功能,比如VMware Workstation, VMware Horizon View 的用户都可以通过拖拽实现主机和虚拟机之间的文件拷贝。最近我进行了调研,并实现在了VMware Horizon view上的DnD自动化测试,做一些经验总结。 为什么使用LDTP + Pywinauto?LDTP 是我常用的UI自动化测试框架,因此主体的对象识别操作都是用...原创 2019-02-17 16:36:38 · 1858 阅读 · 0 评论 -
一个简单的python socket编程
转自:http://openexperience.iteye.com/blog/145701python 编写server的步骤:第一步是创建socket对象。调用socket构造函数。如:socket = socket.socket( family, type )family参数代表地址家族,可为AF_INET或AF_UNIX。AF_INET家族包括Inter转载 2012-06-08 09:05:28 · 564 阅读 · 0 评论 -
Python tips
Sequence:Thus, shoplist[1:3] returns a slice of the sequence starting at position 1, includes position 2 butstops at position 3 and therefore a slice of two items is returned. Similarly, shoplist[原创 2012-07-04 18:58:01 · 497 阅读 · 0 评论 -
Jython小问题-字符编码
WebLogic/WebSphere监控中常用到Jython,就想下一个学学,听说简单易用,结果刚开头就碰到问题了。具体见下:E:\TEMP>jython -iJython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)[IBM J9 VM (IBM Corporation)] on java1.6.0Type "h转载 2012-06-21 17:29:25 · 1560 阅读 · 1 评论 -
Python配置文件解析器ConfigParser 的基本结构、备注和传参
ConfigParser模块实现了基本的配置文件解析,在python3.x,这个模块更名为configparser .1. 配置文件基本结构:[SectionName]key1 = value1 (或者是 key1: value1)key2 = value22. 通过以下函数去获取配置信息:ConfigParser.get(section,option[,raw[,va原创 2011-12-28 23:07:47 · 2045 阅读 · 0 评论 -
Python optparse 解析命令行输入
使用optparse模块解析命令行输入项,python2.7之后不做进一步开发,而是继续开发argparse模块来替代。from optparse import OptionParserparser = OptionParser("%prog :HELP info")parser.add_option("-f", "--file", dest="filename",原创 2012-03-13 18:12:43 · 1364 阅读 · 0 评论 -
Python import
from package import item VS import package.itemThere is nothing wrong with using from Package import specific submodule! In fact this becomes the recommended notationunless the importing modul原创 2012-03-10 12:38:14 · 1247 阅读 · 0 评论 -
Python:Relative import 相对路径 ValueError: Attempted relative import in non-package
包含相对路径import 的python脚本不能直接运行,只能作为module被引用。原因正如手册中描述的,所谓相对路径其实就是相对于当前module的路径,但如果直接执行脚本,这个module的name就是“__main__”, 而不是module原来的name, 这样相对路径也就不是原来的相对路径了,导入就会失败,出现错误“ValueError: Attempted relative impo原创 2012-03-09 19:35:57 · 64875 阅读 · 12 评论 -
python codecs
1. 设置标准输出的编码方式:use getwriter() to get a stream encoder class for a specific encoding. Instantiate the class, passingsys.stdout as the only argument.import codecsimport systext = u'pi: π'# W原创 2012-03-08 13:15:25 · 1853 阅读 · 0 评论 -
Python 性能剖分工具
Python 性能剖分工具From:http://blog.csdn.net/lanphaday/一、profile、cProfile与hotshotprofile、cProfile与hotshot Python 内置了丰富的性能优化工具来帮助我们定位性能瓶颈,如:profile、cProfile和 hotshot。它们易于使用,而且有完备的支持文档可供参考。下面以转载 2012-06-30 07:21:44 · 727 阅读 · 0 评论 -
Python获取本机IP地址
使用Python可以用很简单的方法得到本机IP地址,不过在Windows和Linux下的方法稍有不一样的,Windows下获得IP地址的方法 方法一使用拨号上网的话,一般都有一个本地ip和一个外网ip,使用python可以很容易的得到这两个ip 使用gethostbyname和gethostbyname_ex两个函数可以实现import socketlocalIP =转载 2012-10-24 18:01:58 · 2540 阅读 · 0 评论 -
Python获取当前系统用户名
Python获取当前系统用户名转自http://www.codecho.com/get-current-username-in-python某些时候我们需要获得系统当前的用户名,那么在Pyton中有没有一个可跨平台的方式或者类库支持这一操作呢?最常用的就是getpass模块:123>>> importgetpass>>>转载 2013-01-28 15:44:48 · 27022 阅读 · 1 评论 -
日常Python中使用正则表达式处理字符串
平时常常使用Python的正则表达式进行一些字符串的处理,做一点简单记录:1. 查找字符串中的特定字符串: >>> x = "s321sdd55ii">>> re.findall(r‘\d+', x)['321', '55']2. 把字符串按正则规则切片:>>> x = "sfas sadfaee d serass...原创 2019-02-16 10:36:33 · 1632 阅读 · 0 评论 -
Python 批量转换文件扩展名
简单写了一个,记录一下:#!/usr/bin/python#-*- encoding:utf-8 -*-import osclass ChangeExt: ''' Try to change the extension name of the files in bats a. If not specify the oldSuffix, an原创 2012-06-29 17:48:17 · 742 阅读 · 0 评论 -
Vim as Python IDE on windows
Vim as Python IDE on windows下载安装Python。从Vim的网站下载vim,建议下Self-installing executable的版本。 编辑vim的配置文件_vimrc拷贝vimrc_example里面的东东到_vimrc去掉_vimrc里面的source $VIMRUNTIME/vimrc_example.vim 设置中文支持转载 2013-05-27 07:44:46 · 789 阅读 · 0 评论 -
BeautifulSoup
剖析对象 (BeautifulSoup或 BeautifulStoneSoup的实例)是深层嵌套(deeply-nested), 精心构思的(well-connected)的数据结构,可以与XML和HTML结构相互协调.剖析对象包括2个其他类型的对象,Tag对象,用于操纵像 ,这样的标签;NavigableString对象,用于操纵字符串,如"Page title"和"This is原创 2013-02-03 11:33:49 · 6758 阅读 · 0 评论 -
Python Import机制
Python Import机制文章分类:Python编程模块的搜索路径模块的搜索路径都放在了sys.path列表中,如果缺省的sys.path中没有含有自己的模块或包的路径,可以动态的加入(sys.path.apend)即可。下面是sys.path在Windows平台下的添加规则。1、sys.path第一个路径往往是主模块所在的目录。在交互环境下添加一个空项,它对应当前目录转载 2013-01-30 23:12:07 · 413 阅读 · 0 评论 -
Python异常处理
Python异常处理2008年10月25日 星期六 15:56Python异常处理 (2008-07-08 00:15:17)标签:python 异常处理 exception 分类:学习笔记 Python的异常处理能力是很强大的,可向用户准确反馈出错信息。在Python中,异常也是对象,可对它进行操作。所有异常都是基类Exception的成员。所有异常都从基转载 2013-01-30 23:14:15 · 472 阅读 · 0 评论 -
Python 杂记
tuple: 元组,数组A non-exhaustive list of features which are only available in 3.x releases and most likely won't be backported to the 2.x series:function annotations syntax for keyword-only argu原创 2013-01-30 23:08:31 · 823 阅读 · 0 评论 -
Python模块包中__init__.py文件的作用
用django做开发已经一年多的时间,但基本没注意python模块中__init__.py文件存在的意义,偶然看到对它的介绍吓一大跳,这个文件太重要了模块包:包通常总是一个目录,目录下为首的一个文件便是 __init__.py。然后是一些模块文件和子目录,假如子目录中也有 __init__.py 那么它就是这个包的子包了。差不多就像这样吧:Package1/ __init_转载 2013-01-30 23:11:20 · 735 阅读 · 0 评论 -
Django Admin 模块探究
1. 开启 Admin 模块:settings.py: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', # Uncomment the next line to enable the admi原创 2012-03-02 17:08:20 · 1044 阅读 · 0 评论 -
python urllib2 httplib HTTPConnection
copy from http://hi.baidu.com/chjj910/blog/item/7db5c24fbc699d19b2de0540.htmlpython基于http协议编程:httplib,urllib和urllib2(转)2010-11-11 20:47httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,转载 2012-02-28 00:16:54 · 1510 阅读 · 0 评论 -
Dive into Python 点滴
1. __init__ 方法是可选的,但一旦你定义了, 就必须记得显示调用父类__init__ 方法(如果它定义了的话)。这样更是正确的:无论何时子类想扩展父的行为,后代方法 必须在适当时机,使用适当的参数,显式调用父类方法。2. 下划线- _single_leading_underscore: weak "internal use" indicator. E.g. "from M转载 2012-02-21 14:49:49 · 595 阅读 · 0 评论 -
Python 之string
Python 之stringhttp://www.cnblogs.com/65702708/archive/2010/04/08/1707573.html代码>>> # Replace some items:... a[0:2] = [1, 12]>>> a[1, 12, 123, 1234]>>> # Remove some:... a[0:2]转载 2011-12-06 18:53:16 · 318 阅读 · 0 评论 -
python中的yield
python中的yieldhttp://qiaoqinqie.iteye.com/blog/988412最近在学习django。在看到里面的源码的时候,发现有很多地方使用了yield,不知是干什么的,于是就上网查了一下。呵呵,python的这个yield和java的差别真的是太大了。yield在python2.5以后是一个生成器。也就是说 。如果一个函数里面有yield。那转载 2011-11-30 15:23:17 · 859 阅读 · 0 评论 -
Python fnmatch — Unix filename pattern matching
This module provides support for Unix shell-style wildcards, which arenot the same as regular expressions (which are documented in the re module). The special characters used in shell-style wildca原创 2011-11-30 15:03:20 · 608 阅读 · 0 评论 -
Install MySQL 5 for Python 2.6 (and django) on Windows
Install MySQL 5 for Python 2.6 (and django) on WindowsI've heard a lot about python and his framework Django, But because i love php i never found the time to test python and honestly i didn't fel转载 2011-11-28 14:56:06 · 646 阅读 · 0 评论 -
Python MD5 验证
假设有2个二进制文件(0.bin, 1.bin),用checksum检验内容是否相同 import md5 with open('o.bin', 'rb') as f: s = md5.new(f.read()).hexdigest() with open('1.bin', 'rb') as f: ss = md5.new(f.read()).hex转载 2011-11-17 18:45:55 · 1077 阅读 · 0 评论 -
Python String translate() Method
http://www.tutorialspoint.com/python/string_translate.htmDescription:This method returns a copy of the string in which all characters have been translated using table(constructed with the ma转载 2011-11-17 16:18:38 · 1023 阅读 · 0 评论 -
python glob model
http://www.cnblogs.com/lovemo1314/archive/2011/04/26/2029556.htmlpython glob model说明:1、glob是python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,就类似于Windows下的文件搜索,支持通配符操作,*,?,[]这三个通配符,*代表0个或多个字符,?代表一个转载 2011-11-17 18:32:41 · 388 阅读 · 0 评论 -
改进shutil中的copytree()和move()函数
http://blog.donews.com/limodou/archive/2006/08/08/992239.aspx改进shutil中的copytree()和move()函数最新在修改 NewEdit 中,在目录浏览窗口中增加了对文件和目录进行剪切、拷贝和粘贴的功能。因为要用到对整个目录的操作,因此我使用了shutil模块中的copytree()和move()函数。但转载 2011-11-17 17:12:29 · 3433 阅读 · 0 评论 -
Python 正则表达式 re
flags: re.I (ignore case),re.L (locale dependent),re.M (multi-line),re.S (dot matches all), re.U (Unicode dependent), re.X (verbose), for the entire regular expression.Python off原创 2011-11-08 16:15:45 · 889 阅读 · 0 评论 -
python连接MySQL数据库
http://www.2cto.com/kf/201009/74972.html模块功能:connect()方法 * connect()方法用于连接数据库,返回一个数据库连接对象。如果要连接一个位于host.remote.com服务器上名为fourm的MySQL数据库,连接串可以这样写: db = MySQLdb.connect(host="remo转载 2011-12-06 17:12:48 · 779 阅读 · 0 评论 -
VIM python 自动补全插件pydiction
Python VIM 开发环境配置1. VIM python 自动补全插件:pydiction这是一个相当不错的 Python 代码自动完成的脚本。可以实现下面python代码的自动补全:简单python关键词补全python 函数补全带括号python 模块补全python 模块内函数,变量补全from module import转载 2011-12-11 00:22:54 · 784 阅读 · 0 评论 -
Python的MySQL库
Python的MySQL库http://www.cnblogs.com/wutaotao/archive/2011/05/31/2064963.htmlPython真是个装b的语言,居然连mysql这么流行的数据库,都不提供官方支持有第三方库,MySQLdb, 但这个库的帮助里面,只支持到mysql 5.1操蛋的是,MySQLdb 库安装的时候,居然需要先安装一个mysql s转载 2011-11-28 15:12:24 · 931 阅读 · 0 评论 -
Python 之 tuple
Tuple is an immutable list.Tuples are faster than lists. If you're defining a constant set of values and all you're ever going to do with it is iterate through it, use a tuple instead of a l原创 2012-02-12 15:29:34 · 451 阅读 · 0 评论 -
Python标准模块logging
http://blog.csdn.net/fxjtoday/article/details/6307285开发Python, 一直以来都是使用自己编写的logging模块. 比较土......今天发现python的标准模块的这个功能做的挺好, 记录一下, 以后使用模块来进行logging.对于这个模块的介绍网上也很多, 我也不用自己写了, 比较好的如下,http://c转载 2012-02-01 15:42:32 · 589 阅读 · 0 评论 -
pyatspi
at-spi is the "Assistive Technology Service Provider Interface". . Accessibility is enabling people with disabilities to participate in substantial life activities that include work and the use of原创 2011-12-28 18:56:53 · 793 阅读 · 0 评论 -
Python下划线与命名规范
Python下划线与命名规范http://www.cnblogs.com/yaksea/archive/2011/08/30/2159416.html以下分四种情况说明下划线的作用,python对成员域没有严格控制,大部份只是作为命名规范存在,以下英文部份摘自python官方网站 _single_leading_underscore: weak "internal use"转载 2011-12-15 12:20:54 · 770 阅读 · 0 评论 -
mysql python 汉字乱码的解决方案
mysql python 汉字乱码的解决方案 1.想实现对一个二类文本问题的两种分类方法,首先要对文档集合的文本进行分词,然后建立倒排表,倒排表是借助于mysql数据库的,但是有一个众所周知的事情,mysql插入汉字会出现各种莫名奇妙的情况,首当其冲是插不进去,而获是插进去了,但是显示是乱码,然后将插入后的数据再读到程序中仍然是乱码。这归根结底是编码符号不一致的问题也就是。再解决这个问转载 2011-12-25 23:25:52 · 412 阅读 · 0 评论