Ray's playground

 

随笔分类 -  Python

1 2 3 4 下一页

Script Execution Context(Chapter 3 of Programming Python)
摘要:1importsys23classOutput:4def__init__(self):5self.text=''6defwrite(self,string):7self.text+=string8defwritelines(self,lines):9forlineinlines:10self.write(line)1112classInput:13def__init__(self,input=''):14self.text=input15defread(self,size=None):16ifsize==None:17res,self.text=self.tex 阅读全文

posted @ 2011-04-05 09:56 Ray Z 阅读(299) 评论(0) 推荐(0)

Debuggers and Debugger Design(Chapter 2 of Gray Hat Python)
摘要:The ability to halt a process that is being debugged is achieved by settingbreakpoints. By halting the process, you are able to inspect variables, stackarguments, and memory locations without the process changing any of theirvalues before you can record them. Breakpoints are most definitely the mos. 阅读全文

posted @ 2011-04-02 20:57 Ray Z 阅读(160) 评论(0) 推荐(0)

Setting Up Your Development Environment(Chapter 1 of Gray Hat Python)
摘要:1>>>fromctypesimport*2>>>c_int()3c_long(0)4>>>c_char_p("helloworld!")5c_char_p('helloworld!')6>>>c_ushort(-5)7c_ushort(65531)8>>>seitz=c_char_p("lovespython")9>>>printseitz10c_char_p('lovespython')11>>> 阅读全文

posted @ 2011-04-02 19:50 Ray Z 阅读(229) 评论(0) 推荐(0)

System Tools(Chapter 2 of Programming Python)
摘要:1defmore(text,numlines=15):2lines=text.splitlines()3whilelines:4chunk=lines[:numlines]5lines=lines[numlines:]6forlineinchunk:7printline8iflinesandraw_input('More?')notin['y','Y']:9break1011if__name__=='__main__':12importsys13more(open(sys.argv[1]).read(),10)14 1>&g 阅读全文

posted @ 2011-04-02 11:36 Ray Z 阅读(240) 评论(0) 推荐(0)

Hello world for tornado
摘要:1importtornado.ioloop2importtornado.web34classMainHandler(tornado.web.RequestHandler):5defget(self):6self.write("helloworld")78application=tornado.web.Application([(r"/",MainHandler),])910if__name__=="__main__":11application.listen(8888)12tornado.ioloop.IOLoop.instance( 阅读全文

posted @ 2011-04-01 12:16 Ray Z 阅读(357) 评论(2) 推荐(0)

Getting Started(Chapter 1 of Python 2.6 Text Processing)
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1importsys2importstring34CHAR_MAP=dict(zip(string.ascii_lowercase,string.ascii_lowercase[13:26]+5string.ascii_lowercase[0:13]))67defrotate13_letter(letter):8"""9Returnthe13-charrot 阅读全文

posted @ 2011-02-11 23:26 Ray Z 阅读(192) 评论(0) 推荐(0)

Recipe 1.12. Controlling Case(Python Cookbook)
摘要:capitalizeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1'onetWothrEe'.capitalize()2'Onetwothree'3'hellosunshine'.title()4'HelloSunshine'5"abc".upper()6'ABC'7"RAY".lower()8'ray'9importstring10notrans=string.maketrans('','')11de 阅读全文

posted @ 2010-12-23 22:00 Ray Z 阅读(190) 评论(0) 推荐(0)

Recipe 1.11. Checking Whether a String Is Text or Binary(Python Cookbook)
摘要:[代码] 阅读全文

posted @ 2010-12-23 21:14 Ray Z 阅读(186) 评论(0) 推荐(0)

Recipe 1.10. Filtering a String for a Set of Characters(Python Cookbook)
摘要:[代码] 阅读全文

posted @ 2010-12-22 20:31 Ray Z 阅读(186) 评论(0) 推荐(0)

Recipe 1.9. Simplifying Usage of Strings' translate Method(Python Cookbook)
摘要:[代码] 阅读全文

posted @ 2010-12-21 09:39 Ray Z 阅读(132) 评论(0) 推荐(0)

Recipe 1.8. Checking Whether a String Contains a Set of Characters(Python Cookbook)
摘要:maketransCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1intab="aeiou"2outtab="12345"3fromstringimportmaketrans4trantab=maketrans(intab,outtab)5s="thisisastringexample...wow!"6prints.translate(trantab)7th3s3s1str3ng2x1mpl2...w4w![代 阅读全文

posted @ 2010-12-20 22:18 Ray Z 阅读(372) 评论(0) 推荐(0)

Recipe 1.7. Reversing a String by Words or Characters(Python Cookbook)
摘要:reverseCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1astring="helloray"2revwords=astring.split()3revwords4['hello','ray']5revwords.reverse()6revwords7['ray','hello']8revwords=''.join(revwords)9revwords10'rayhello'11importre 阅读全文

posted @ 2010-12-19 14:21 Ray Z 阅读(163) 评论(0) 推荐(0)

Recipe 1.6. Combining Strings(Python Cookbook)
摘要:stringCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1importoperator2pieces=['a','b','c']3largestring=reduce(operator.add,pieces)4largestring5'abc'6faststring=''.join(pieces)7faststring8'abc'9formatstring='%sis%s'%('ray','coding 阅读全文

posted @ 2010-12-19 11:43 Ray Z 阅读(152) 评论(0) 推荐(0)

Recipe 1.5. Trimming Space from the Ends of a String(Python Cookbook)
摘要:[代码] 阅读全文

posted @ 2010-12-18 23:05 Ray Z 阅读(137) 评论(0) 推荐(0)

Recipe 1.4. Aligning Strings(Python Cookbook)
摘要:alignCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1print'|','hej'.ljust(20),'|','hej'.rjust(20),'|','hej'.center(20),'|'2|hej|hej|hej|3print'hej'.center(2)4hej5print'hej'.center(20,'+')6++++++++hej+++++++++ 阅读全文

posted @ 2010-12-18 11:09 Ray Z 阅读(175) 评论(0) 推荐(0)

Recipe 1.3. Testing Whether an Object Is String-like(Python Cookbook)
摘要:isAStringCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1defisAString(anobj):2returnisinstance(anobj,basestring)34a="hello"5isAString(a)6True7b='t'8isAString(b)9True10c=[]11isAString(c)12False13classMyString(str):14pass1516 阅读全文

posted @ 2010-12-17 22:29 Ray Z 阅读(122) 评论(0) 推荐(0)

Recipe 1.2. Converting Between Characters and Numeric Codes(Python Cookbook)
摘要:[代码] 阅读全文

posted @ 2010-12-16 11:13 Ray Z 阅读(148) 评论(0) 推荐(0)

Recipe 1.1. Processing a String One Character at a Time(Python Cookbook)
摘要:setCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1importsets2magic_chars=sets.set('abracadabra')3magic_chars=sets.Set('abracadabra')4poppins_chars=sets.Set('supercalifragilisticexpialidocious')5print''.join(magic_chars&poppins_chars) 阅读全文

posted @ 2010-12-15 21:52 Ray Z 阅读(171) 评论(0) 推荐(0)

Breaking Tight Coupling by using Mock Objects(Chapter 4 of Python Testing Beginner's Guide)
摘要:mockCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1>>>frommockerimportMocker2>>>mocker=Mocker()3>>>func=mocker.mock()4>... 阅读全文

posted @ 2010-11-30 21:51 Ray Z 阅读(166) 评论(0) 推荐(0)

Doctest: The Easiest Testing Tool(Chapter 2 of Python Testing Beginner's Guide)
摘要:test.txtCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1ThisisasimpledoctestthatcheckssomeofPython'sarithmeticoperations.2>>>2+2344>>&... 阅读全文

posted @ 2010-11-28 14:04 Ray Z 阅读(295) 评论(0) 推荐(0)

1 2 3 4 下一页

导航