随笔分类 - Python
摘要:8 Trees8.1 general treestree ADT计算depth和height8.2 二叉树决策树二叉树 ADT8.3 Implementing Trees数组表示得二叉树8.4 树的遍历算法宽度优先遍历中序遍历二叉搜索树python实现树遍历8 Trees8.1 general tr...
阅读全文
摘要:werkzeug构建'url shortly'应用0: basic wsgi1: creating the folders2: the base structure3: 环境4: routing5: first view6: redirect view7: detail viewwerkzeug构建...
阅读全文
摘要:要使我们的对象支持with语句,必须为它实现 __enter__和__exit__方法。先看一个例子:from socket import socket, AF_INET, type=SOCK_STREAMclass lazyConnection: def __init__(self, add...
阅读全文
摘要:hello world WSGI appWSGI应用WSGI环境用environ参数创建Request请求Responseshello world WSGI appdef application(environ, start_response): start_response( ...
阅读全文
摘要:yosemite系统用brew安装mysql可以参考: http://segmentfault.com/a/1190000000438233安装mysqldb: pip install mysql-python简单例子import MySQLdb as mdbimport systry: co...
阅读全文
摘要:Functions as objects and closurespython中的函数是first-class objects,即它们可以作为参数传递到其他函数中,可以存储到数据结构中,也可以作为函数的返回值一个简单例子# foo.pydef callf(func): return func(...
阅读全文
摘要:python_files_operationsfiles, file objectsopen(name [, mode [, bufsize]])eg:file = "data.txt"f = open(file, 'r')f = open(file, 'w')'r':read'w':write'a...
阅读全文
摘要:python3之前的版本用Tkinter,之后用的是tkinter最简单的使用Tkinter的代码,首先要Tk()建立一个窗口,然后加进各种Widgetfrom Tkinter import *window = Tk()label = Label(window, text = "Welcome to...
阅读全文
摘要:1. 反斜杠的困扰(The Backslash) 有时候需要匹配的文本带有'\',如'\python',因为正则表达式有些特殊字符有特殊意义,所以需要前面加上'\'来消除特殊意义,这里匹配的正则表达式是'\\python',这时候如果要编译这个正则表达式需要re.compile('\\\\pyth...
阅读全文
摘要:1. urlopen可以给一个Request Object返回一个response object,read()读取相应对象的内容,这时候的print(the_page)可以输出网页的html内容1 import urllib22 3 req = urllib2.Request('http://www...
阅读全文

浙公网安备 33010602011771号