python
bigbugor
程序员
展开
-
flask 获取 get post 请求提交的参数
request.values.get("****")原创 2015-06-02 09:03:02 · 7347 阅读 · 0 评论 -
python 倒读 一个文件,从最后一行往前读
#!/usr/bin/env python# -*-mode: python; coding: iso-8859-1 -*-## Copyright (c) Peter Astrand import osimport stringclass BackwardsReader: """Read a file line by line, backwards"""原创 2014-04-04 16:23:01 · 15218 阅读 · 0 评论 -
Python中有很多类似__**__的函数
__init__ 是类的 构造函数 __le__ __ne__ 是 运算符函数 __le__ 是 <=__ne__ 是 !=原创 2014-03-24 15:36:31 · 510 阅读 · 0 评论 -
python中map、filter、reduce 函数使用方法
三个函数比较类似,都是应用于序列的内置函数。常见的序列包括list、tuple、str。1.map函数map函数会根据提供的函数对指定序列做映射。map函数的定义:map(function, sequence[, sequence, ...]) -> list通过定义可以看到,这个函数的第一个参数是一个函数,剩下的参数是一个或多个序列,返回值是一原创 2014-03-24 15:18:29 · 948 阅读 · 0 评论 -
python 按照gb2312做url编码
import urllib2 urllib2.quote("攻克平台")原创 2014-05-06 15:19:30 · 2293 阅读 · 0 评论 -
python中怎样修改全局变量
>>> a=1>>> def func():global aa =4>>> if __name__=='__main__':func()print a原创 2014-03-24 13:40:01 · 1862 阅读 · 0 评论 -
python读取xml放入dict字典中
xml version="1.0" encoding="utf-8"?>config desc="Line8Center" line="8"> stations> ip base="192.168.8" /> station name="市光路站" /> station name="嫩江路站" />原创 2014-03-24 13:03:24 · 8839 阅读 · 0 评论 -
python中使用网络爬虫下载图片
import reimport urllib def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(html): reg = r'src="(.+?\.jpg)" pic_ext'原创 2014-03-24 16:07:21 · 799 阅读 · 0 评论 -
python中常用的正则表达式
元字符1.匹配元字符:. 它匹配除了换行字符外的任何字符,在 alternate 模式(re.dotaLL)下它甚至可以匹配换行^ 匹配行首。除非设置 MULTILINE 标志,它只是匹配字符串的开始。$ 匹配行尾,行尾被定义为要么是字符串尾,要么是一个换行字符后面的任何位置。[] 它们常用来指定一个字符类别,所谓字符类别就是你想匹配的一个字符集\ 反斜杠后原创 2014-03-24 15:51:08 · 475 阅读 · 0 评论 -
python中@staticmethod 、@classmethod 与一般方法的区别
一般方法使用 类生成的对象调用静态方法用类直接调用类方法用类直接调用类当参数传入方法如下面例子:###################################class Person: def __init__(self): print "init" @staticmethod def say原创 2014-03-24 14:14:23 · 1457 阅读 · 0 评论 -
python远程调用webservice服务
第一步:首先要安装suds库,在命令行下输入easy_install suds,等待程序自动安装,待出现 Finished processing dependencies for suds 就安装成功了!第二步:导入包from suds.client import Client,创建一个websevice类1 from suds.client import Client 2原创 2014-04-03 17:41:59 · 1740 阅读 · 0 评论 -
python中把一数据库表 数据存入另一个数据库中
把'aa'数据库中数据存入default############################################## student =Student.objects.using('aa').order_by('id').filter(pk__gt=1)[:3] print len(student) for items in student:原创 2014-03-24 10:48:41 · 5448 阅读 · 0 评论 -
python base64 加密 解密
# -*- coding: UTF-8 -*-import base64if '__main__'==__name__: key='H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZ原创 2014-04-18 13:19:42 · 4448 阅读 · 0 评论 -
python中进程池例子
在利用Python进行系统管理的时候,特别是同时操作多个文件目录,或者远程控制多台主机,并行操作可以节约大量的时间。当被操作对象数目不大时,可以直接利用multiprocessing中的Process动态成生多个进程,10几个还好,但如果是上百个,上千个目标,手动的去限制进程数量却又太过繁琐,这时候进程池Pool发挥作用的时候就到了。 Pool可以提供指定数量的进程,供用户调用,当有原创 2014-03-25 11:05:59 · 1490 阅读 · 0 评论 -
python中俩个对象的比较方法
Python有两种方法可以测试相等性:1、 == 操作符测试值得相等性。Python运行相等测试,递归地比较所有的内嵌对象。(比较内容是否相等)2、 is 表达式测试对象的一致性。Python测试二者是否是同一个对象。(比较内存地址是否相同)例如: lst1 = [1,2,3,4,[5,6]] lst2 = [1,2,3,4,原创 2014-03-25 10:16:00 · 2000 阅读 · 0 评论 -
python简单操作redis
8178°C上篇文章简单说了下linux安装redis的过程,这里就是用python代码稍加演练,首先用pip安装redis:sudo pip install redis然后就可以在python中调用了,下面写了些基础的东西,按着redis实战里面的介绍来写。关于redis的复杂的使用以后用到再来学习,代码更直观:import rediscache = redis.原创 2015-01-04 17:23:54 · 709 阅读 · 0 评论 -
python装饰器实现线程同步
import threadingdef tryfinally(finallyf): u"returns a decorator that adds try/finally behavior with given no-argument call in the finally" print "tryfinally" def decorator(callable): p原创 2014-08-05 10:18:26 · 1033 阅读 · 0 评论 -
python 3Des 加密
import hashlib;from Crypto.Cipher import DES3import base64def create_key(sk): r=hashlib.md5(sk).digest() return r+r[:8]def init_str(s): l=len(s) % 16 if l!=0:原创 2014-07-10 10:49:08 · 12694 阅读 · 0 评论 -
python flask model 序列化
class DictSerializable(object): def as_dict(self,*args): result = OrderedDict() keys=args or self.__mapper__.c.keys() for key in keys: if hasattr(self,key)原创 2014-06-17 16:13:32 · 5098 阅读 · 0 评论 -
python 运用 flask框架分页
Model.query.filter_by(id=0).paginage(1,2)Model.query.filter(id>0).paginaate原创 2014-06-16 16:00:51 · 2427 阅读 · 0 评论 -
python 获取当前日期 星期
from datetime import datetimed =datetime.today() #获取当前日期时间d.isoweekday() #获取时间周几原创 2014-07-04 09:12:28 · 6044 阅读 · 0 评论 -
python 字符串转化成数组
k='(1,2,3),4,5,(6,7)'eval(k)原创 2014-07-04 17:29:01 · 8897 阅读 · 0 评论 -
python 正则表达式判断邮箱格式是否正确
import redef validateEmail(email): if len(email) > 7: if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None: return 1 r原创 2014-07-22 17:35:24 · 14271 阅读 · 0 评论 -
Python 文件操作
1、文件写入12345678910111213141516171819202122import timeimport random #打开模式列表:#w 以写方式打开,#a 以追加模式打开 (从 EOF 开始, 必要时创建新原创 2014-05-15 14:55:16 · 886 阅读 · 0 评论 -
python 实现 全角字符 传转换成 半角字符串
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.>>> def strQ2B(ustring):#把全角字符串转半角 ustr原创 2014-05-09 16:44:50 · 1796 阅读 · 0 评论 -
python操作数据库模板 MySQLdb模块
Python中的mysql操作可以使用MySQLdb模块来完成。它符合Python社区设计的Python Database API SpecificationV2.0标准,所以与其他的数据库操作的API,如SQLite等基本类似。1.连接的建立与释放建立连接时可用connect函数,它返回一个Connection类型对象conn = MySQLdb.connect('l原创 2014-04-09 18:05:36 · 1412 阅读 · 0 评论 -
python中的常用模块
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctypes:用来调用动态链接库DBUtils:数据库连接池django:一个WEB frameworkdocutils:用来写文档的dpkt:数据包的解包和组包MySQLd原创 2014-03-26 18:09:13 · 1032 阅读 · 0 评论 -
python+django读取json数据,同步数据库
[["account_detail", 1],["account", 1], ["account_recharge", 3]]#########################################################!/usr/bin/python#coding=utf-8from django.core.management import se原创 2014-03-20 21:55:57 · 7190 阅读 · 0 评论 -
python webservice gzip压缩与解压缩
################################ Model.py# -*- coding: UTF-8 -*-__author__ = 'fanyunlei'import gzipfrom cStringIO import StringIOimport binasciidef zipString(uncom_data): buf =原创 2014-04-17 17:51:20 · 1854 阅读 · 0 评论 -
python webservice sax xml解析
# -*- coding: UTF-8 -*-__author__ = 'fanyunlei'import xml.saximport urlliballData=[]class MovieHandler( xml.sax.ContentHandler ): def __init__(self): self.air={} self.Curre原创 2014-04-17 15:15:11 · 1364 阅读 · 0 评论 -
django+python本地日志log源码
def get_logger_local(logname,modlename): root_logger = logging.getLogger(logname) if len(root_logger.handlers)==0: path=os.path.join(sys.path[0],'logs/').replace('\\','/')原创 2014-03-18 13:27:17 · 914 阅读 · 0 评论 -
python将excel数据导入到数据库中
excel数据:******************************************************************************************# Create your views here.# -*- coding: utf-8 -*-import modelsfrom models import Studen原创 2014-03-19 10:10:04 · 6365 阅读 · 0 评论 -
python将mysql数据库表中数据导入excel表格中
# Create your views here.# -*- coding: utf-8 -*-import modelsfrom models import Studentfrom django.shortcuts import render_to_response,renderfrom pyExcelerator import *import time# -原创 2014-03-19 09:35:33 · 3509 阅读 · 0 评论 -
python线程池实例
from multiprocessing import Poolimport timedef f(x): time.sleep(1) return x*xif __name__ == '__main__': pool = Pool(processes=4) result = pool.apply原创 2014-03-17 16:30:29 · 611 阅读 · 0 评论 -
python多进程通信例子
客户端:import webtulfrom multiprocessing.connection import Client a = 0try: while True: a += 1 address = ('10.33.41.112', 6666) conn = Clien原创 2014-03-17 15:53:35 · 1261 阅读 · 0 评论 -
Python正则表达式的用法
本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例。本文的内容不包括如何编写高效的正则表达式、如何优化正则表达式,这些主题请查看其他教程。注意:本文基于Python2.4完成;如果看到不明白的词汇请记得百度谷歌或维基,whatever。 尊重作者的劳动,转载请注明作者及原文地址 >.html1. 正则表达式基础原创 2014-03-27 17:38:41 · 1094 阅读 · 0 评论 -
python开发webservice例子
服务器段代码:import soaplibfrom soaplib.core.server import wsgifrom soaplib.core.service import DefinitionBasefrom soaplib.core.service import soapfrom soaplib.core.model.clazz import Arrayf原创 2014-03-17 15:18:55 · 1208 阅读 · 0 评论 -
django+python开发的网站怎么静态引用img图片
html中引用图片路径: url.py添加配置:urlpatterns = patterns('', # Examples: # url(r'^$', 'csvt02.views.home', name='home'), # url(r'^csvt02/', include('csvt02.foo.urls')), # Uncomm原创 2014-03-18 10:58:30 · 1943 阅读 · 1 评论 -
django缓存机制
动态网站的问题就在于它是动态的。 也就是说每次用户访问一个页面,服务器要执行数据库查询,启动模板,执行业务逻辑以及最终生成一个你所看到的网页,这一切都是动态即时生成的。 从处理器资源的角度来看,这是比较昂贵的。对于大多数网络应用来说,过载并不是大问题。 因为大多数网络应用并不是washingtonpost.com或Slashdot;它们通常是很小很简单,或者是中等规模的站点,只有很原创 2014-03-18 09:54:23 · 2344 阅读 · 0 评论 -
extjs常用函数
Ext.util.Observable:一个抽象基类,为事件机制的管理提供一个公共接口,如果你希望的类可以有事件,就继承它吧 Ext.apply:如果只传入两个参数,则将C继承D的所有方法属性,如果定义了B则每次都先继承B的方法属性然后再继承D的方法属性,即B是默认继承对象 1、Ext.apply(Object obj, Object config, Object defaults ) :原创 2014-03-17 22:29:57 · 564 阅读 · 0 评论