一、Flask简介Flask 是一个 Python 实现的 Web 开发微框架。官网:http://flask.pocoo.org/二、Demo1、代码结构.├── blog.py├── static│ ├── css│ │ └── index.css│ ├── images│ │ ├── cat....
分类:
编程语言 时间:
2014-12-31 15:48:17
阅读次数:
285
demo#!/usr/bin/pythonclass Person: name = 'jim' age = 25 def say(self): print 'My name is ' + self.name + ', and age is ' + str(self.a...
分类:
编程语言 时间:
2014-12-31 14:17:44
阅读次数:
188
字符串定义 :字符串(String)是一个字符的序列使用成对的单引号或双引号括起来one_quote_str = 'Hello World!'two_quote_str = "Hello World!"?或者三引号("""或''') 保留字符串中的全部格式信息 ''' this isa t....
分类:
编程语言 时间:
2014-12-30 16:30:37
阅读次数:
324
# -*- coding: utf-8 -*-import argparseargs = "-f hello.txt -n 1 2 3 -x 100 -y b -z a -q hello @args.txt i_am_bar -h".split() # 使用@args.txt要求fromfile_p...
分类:
编程语言 时间:
2014-12-30 13:11:57
阅读次数:
212
Python中的构造函数是形如def__init__(self),例如classBird:
def__init__(self):
self.hungry=True
defeat(self):
ifself.hungry:
print‘Ahhhh‘
self.hungry=False
else:
print‘no,thx‘
实例化类Bird对象b:
b=Bird()
b.eat()
b.eat()
Ahhhh
no,thx假设现在Bird有一个子类So..
分类:
编程语言 时间:
2014-12-30 09:20:32
阅读次数:
166
一、安装MySQL-python# yum install -y MySQL-python二、打开数据库连接#!/usr/bin/pythonimport MySQLdbconn = MySQLdb.connect(user='root',passwd='admin',host='127.0.0.1...
分类:
数据库 时间:
2014-12-29 19:53:38
阅读次数:
192
python:模块导入:from模块名import方法名变量a=100s=‘helloworld‘d=1.99b=Trueif条件:执行语句while条件:循环语句for变量inrange(起,终)#比如foriinrange(1,10)表示i从1变换到9格式化语句比如:print‘%sisyoufunnyfriendps%d‘%(‘5x9x5‘,99);函数defsayHello():print‘helloworl..
分类:
编程语言 时间:
2014-12-28 02:00:47
阅读次数:
180
# coding=utf-8
#一 初始列表
fruits = ["apple","banama","peach"]
print fruits
print fruits[0]
#列表长度
print len(fruits)
#尾部追加一个数据项
fruits.append("watermelon")
print fruits
#尾部删除一个数据项
fruits.pop()
print fruit...
分类:
编程语言 时间:
2014-12-27 23:12:48
阅读次数:
436
堆(heap):优先队列的一种,使用优先队列能够以任意顺序增加对象,并且能在任意时间(可能在增加对象的同时)找到(也可能是移除)最小元素,比用于列表中min的方法要高效。Python中并没有独立的堆类型,只有一个包涵一些堆操作函数的模块,这个模块叫heapq.import heapq1.heapq....
分类:
编程语言 时间:
2014-12-26 18:23:16
阅读次数:
225
本文不涉及正则表达式本身的内容,只记一下python中正则的用法及常用方法。一、re模块python中用re模块进行正则处理>>>import re>>>s = r'abc'>>>re.findall(s,'aaaabcaaaaa')['abc']或先编译(会更快):>>> import re>>>...
分类:
编程语言 时间:
2014-12-26 18:09:17
阅读次数:
150