自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(52)
  • 资源 (1)
  • 收藏
  • 关注

翻译 PEP 8

代码编排:1、使用4个空格缩进2、每行字符的不超过79个3、top-level函数和类的定义之间空两行4、源文件编码,python3用utf-8,python2用ASCII5、不要在一句话中import 多个库import顺序:标准库、第三方库、自己的库  每类库之间用一空行分隔空格使用:函数默认参数使用的赋值符左右省略空格Yes: sp

2014-03-20 11:01:04 564

原创 截断文件 truncate

truncate(size=None)Resize the stream to the given size in bytes (or the current position ifsize is not specified). The current stream position isn’t changed. This resizing can extend or reduce t

2013-12-05 14:55:58 1070

转载 How to send custom http_headers for RPC calls using python xmlrpclib?

from xmlrpclib import ServerProxy, Transport, Errorclass SpecialTransport(Transport): def send_content(self, connection, request_body): print "Add your headers here!" connecti

2013-11-28 09:01:03 653

转载 Python执行系统命令的方法 os.system(),os.popen(),commands

转载:http://my.oschina.net/renwofei423/blog/17403最近在做那个测试框架的时候发现 Python 的另一个获得系统执行命令的返回值和输出的类。最开始的时候用 Python 学会了 os.system() 这个方法是很多比如 C,Perl 相似的。os.system('cat /proc

2013-11-19 17:43:12 1053

转载 Ubuntu 13.04中源码方式安装MySQL 5.5.33

转载:http://lssrc.com/archives/385环境:Ubuntu 13.04数据库:MySQL 5.5.331.下载MySQL 5.5.33源码,地址http://dev.mysql.com/downloads/mysql/5.5.html#downloads2.删除已安装过的MySQLcarl@Carl-U:~$ 

2013-11-16 00:23:59 1831

原创 python 描述器,及property 的实现

参考:https://pyzh.readthedocs.org/en/latest/Descriptor-HOW-TO-Guide.html一个对象只要定义了  __get__(self,instance,owner),__set__(self,instance,value),__delete__(self,instance)__其中的一个或多个,就是一个描述器。其中s

2013-11-15 10:05:16 1144

原创 bytes.fromhex()

while True:            byte=bf.read(1)            if not byte:                bOver=True                break            byte,=struct.unpack('B',byte)            if sign==0 and byte==0:

2013-11-14 15:15:39 13653

转载 Python中的时区处理

转载:http://www.zlovezl.cn/articles/29/因为自己写的东西是跑在米国的原因,所以时区问题是必须要解决的。之前的Django应用比如这个blog对于时区的处理直接在settings.py里面设置TIME_ZONE就可以,但是web.py就需要自己去处理这个问题了。通过阅读Django的代码发现,设置时区只要利用time模块的tzset方法就可以(U

2013-11-13 09:40:25 1366

转载 python 元类

转载:https://pyzh.readthedocs.org/en/latest/python-questions-on-stackoverflow.html#id1           http://blog.csdn.net/gzlaiyonghao/article/details/3048947           http://hi.baidu.com/thinkinginlam

2013-11-11 22:09:57 856

原创 functools

functools.partialint2=functools.partial(int,base=2)print(int2('10'))>>>2未使用functools,函数被装饰后,文档字符丢失def wrap(fn): def wraped(*args,**kw): print('wraped') return f

2013-11-11 15:04:45 719

原创 escape

xml,html的编码和解码xhtml_escape(value):    """Escapes a string so it is valid within HTML or XML."""xhtml_unescape(value):    """Un-escapes an XML-escaped string."""json的编码和解码json_encode(value):    "

2013-11-09 22:40:58 536

原创 util

classObjectDict(dict):classGzipDecompressor(object):def import_object(name):    """Imports an object by name. import_object('x') is equivalent to 'import x'. import_object('

2013-11-09 21:40:06 453

转载 __setattr__ __setattribute__

转载来至:http://www.cnblogs.com/bettermanlu/archive/2011/06/22/2087642.htmlpython 再访问属性的方法上定义了__getattr__() 和 __getattribute__() 2种方法,其区别非常细微,但非常重要。如果某个类定义了 __getattribute__() 方法,在 每次引用属性或

2013-11-08 14:51:12 2130 2

原创 表示一段 bytes

b'\x10\x0\x0\x0\x10\x0\x0\x0' 这样写不正确必须b'\x10\x00\x00\x00\x10\x00\x00\x00'\x00 必须是两个0

2013-10-25 17:34:08 497

原创 csv

csv.reader(csvfile,dialect='excel', **fmtparams)返回一个reader 对象,将按照行遍历csvfile。csvfile 可以是任何支持iterator 并且__next()__返回一个字符串的对象。文件对象和列表都可以。如果csvfile是个文件对象,用open函数式,应指定关键之 newline=''  。eg:file=open(

2013-10-24 16:42:22 2460

原创 urllib.urlparse

urllib.parse.urlparse(urlstring,scheme='', allow_fragments=True)scheme:设置默认值allow_fragments:是否允许fragment>>> from urllib.parse import urlparse>>> o = urlparse('http://www.cwi.nl:80/%7Eguido/

2013-10-23 16:20:10 1290

原创 functools

import functoolsdef foo(a,b): return a+bprint(foo(3,4))7foo=functools.partial(foo,b=8)print(foo(3))11print(foo(3,b=4)) 7functools.reduce(function,iterable[, initializer])

2013-10-23 13:55:13 680

转载 python raise

原地址:http://openhome.cc/Gossip/Python/TryRaise.htmlexcept後若不接上任何例外型態,則表示捕捉所有例外,這包括了所有的系統例外,有時這並不是你想要的行為。例如,下面這個程式,無法透過KeyboardInterrupt來中斷迴圈:while True:    try:        print('Run it....')

2013-10-23 11:21:00 9952

原创 argparse 模块(一)

class argparse.ArgumentParser(prog=None, usage=None, description=None,epilog=None, parents=[], formatter_class=argparse.HelpFormatter, prefix_chars='-',fromfile_prefix_chars=None, argument_default=Non

2013-10-22 22:45:30 1209

原创 re

_URL_RE = re.compile(to_unicode(r"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)"""))

2013-10-17 10:05:23 513

原创 re sub

_XHTML_ESCAPE_RE = re.compile('[&<>"\']')_XHTML_ESCAPE_DICT = {'&': '&', '': '>', '"': '"', '\'': '''}def xhtml_escape(value): """Escapes a string so it is valid within

2013-10-15 15:04:45 586

原创 list sort排序

files=['ik\\ikc000dir\\0.png', 'ik\\ikc000dir\\1.png', 'ik\\ikc000dir\\10.png', 'ik\\ikc000dir\\11.png', 'ik\\ikc000dir\\12.mmd', 'ik\\ikc000dir\\13.mmd', 'ik\\ikc000dir\\14.mmd', 'ik\\ikc000dir\\15.m

2013-10-15 10:35:44 662

原创 cp932 Shift_JIS

a

2013-10-15 10:09:43 1375

原创 decode('unicode_escape')

a='汉字'print(a)b=a.encode('unicode_escape')print(b)c=b.decode('utf-8')print(c)输出:汉字b'\\u6c49\\u5b57'\u6c49\u5b57

2013-10-14 11:41:19 6090

原创 python enumerate

def enumerate(collection): 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...' i = 0 it = iter(collection) while 1: yield (i, it.next()) i += 1

2013-10-11 21:53:00 512

原创 python \x0d\x0a \x0a

在windows下,python 用 ‘r' 方式写入文件时,回车换行想写成'\r\n'要想写入二进制文件的文件中,只有\n 没有\r,则 必须以 二进制格式创建,写入时将 字符串编码成要保存的格式:For instance    fp=open(filname,'wb')    fp.write(fdata.encode('utf-8'))    fp.clo

2013-09-29 12:46:56 7714

原创 apktool 重新编译资源

用apktool  编译一次程序后,改变其资源,需要删掉**\build\apk\resources.arsc  文件,再重新打包。

2013-09-29 09:46:43 853

原创 vim Select Mode

gh       Start characterwise selectiongH      Start linewise selectiongCTRL-H      Start block selectionCTRL-O command switches from selection mode to visual mode for one command.CTRL-G co

2013-09-28 23:04:54 2619

原创 vim Visual Mode

1         The $ commandIn the block visual mode ,the $ command causees the selection to be extended to the end of all the lines in the selection2         Selecting ObjectsThe 'aw' command ,f

2013-09-28 22:22:32 900

原创 vim Sessions

1         The following command creates a session file::mksession file2         Later if you want to resotre this session,you can use this command::source file 3           If you want

2013-09-28 21:48:02 567

原创 vim Buffer

1           You can explicitly add it with the following command::badd file2            Delete a buffer,The :bdelete command deletes a buffer,You can specify the buff by name:bdelete file.c

2013-09-28 21:34:10 675

原创 vim windows

1           CTRL-Wj goes to the next window and CTRL-Wk goes to the preceding oneCTRL-Wt            Go to the top windowCTRL-Wb          Go to the bottom windowCTRL-Wp          Go to the window

2013-09-28 01:19:56 524

原创 vim viminfo

The viminfo file is designed to store information on marks as well as the following:Command-line historySearch-string historyInput-line historyRegistersMarksBuffer listGlobal variables

2013-09-28 00:33:22 1132

原创 vim Multiple Registers

1             "ayy             yy puts the current line in the a register                  When you use the uppercase versino of a register ,say  "Ayy ,you append the text to what is already in the

2013-09-26 23:48:43 743

转载 vim ide 配置

原贴:http://blog.csdn.net/bokee/article/details/6633193工欲善其事,必先利其器。一个强大的开发环境可以大大提高工作效率。好吧,我知道这是废话。。。不过,我想一定有很多跟我一样打算进入Linux平台开发的新手,一开始都为找不到一个像Windows下的VS那样可以一键安装并且功能几乎完美无缺的开发工具而郁闷不已,甚至打算

2013-09-26 21:22:11 573

转载 vim 中Ctags的安装和使用

原贴:http://blog.csdn.net/duguteng/article/details/7412652这两天看到网上有将vim 改造成功能强大的IDE的blog,突然心血来潮,亲身经历了一下。网友的帖子都不错,我这里只是将各种插件分开罗列,然后加上一些使用技巧。希望本文对你有所帮助!『插件介绍』Ctags工具是用来遍

2013-09-26 21:20:41 513

原创 vim python map exec

map :call CompileRun()func CompileRun()    exec 'w'    if &filetype == 'python'        exec '!/usr/bin/python3 %'    endifendfunc

2013-09-26 20:52:02 719

转载 cookie和session的区别

原作者:施杨(施杨's Think out)出处:http://shiyangxt.cnblogs.com本文版权归原作者和博客园共有,欢迎转载,但未经原作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则原作者会保留追究法律责任的权利。cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案。同时我们也看到,由于采用

2013-09-26 10:33:32 544

转载 XML中的转义字符

TML中的转义字符  HTML中,&等有特别含义,(前两个字符用于链接签,&用于转义),不能直接使用。使用这三个字符时,应使用他们的转义序列,如下所示:& 或 &&和< 或 小于号> 或 >>大于号""

2013-09-26 09:40:42 656

原创 vim Search

1        大小写set        smartcaseset       ignorecaseset      noignorecase2             When set nowrapscan,when the search hits the end of the file,an error message displaysset      no

2013-09-25 23:24:55 693

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除