Python
Koopos
这个作者很懒,什么都没留下…
展开
-
Python写Excel文件
pip install pyExcelerator这个就是写Excel需要导入的包from pyExcelerator import *w=Workbook() //工作簿创建ws=w.add_sheet("name") //添加表ws.write(0,0,"row00")ws.write(0,1,"row01")ws.write(1,0,"col10")ws.write(1,1,"co转载 2015-08-24 19:23:47 · 322 阅读 · 0 评论 -
Python json.dumps
import jsons={}s["required"]="get"b=[]b.append("i")json.dumps(b)json.dumps(s)原创 2015-09-23 10:30:51 · 527 阅读 · 0 评论 -
Python opencv2 人脸识别
numpy下载1.9.1 http://sourceforge.net/projects/numpy/files/NumPy/1.9.1/ opencv下载2.4.10 http://sourceforge.net/projects/opencvlibrary/files/opencv-win/ Python opencv 教程 http://pan.baidu.com/s/1jG62bh原创 2015-09-18 13:45:30 · 698 阅读 · 0 评论 -
Python __del__
class Life: def __init__(self,name): self.name=name def __del__(self): print "goodbye",self.namebrain=Life("lshaha")brain="qwe" => out: goodbye lshaha转载 2015-09-17 23:50:27 · 388 阅读 · 0 评论 -
Python Django rest_framework
Rest—面向资源的架构其实Django默认的Admin就是一个很好地rest架构风格的设计。 /poll/admin/user/1 =>第一个user对象(id作为最后一个url的分界。)rest_framework一个比较好的框架可以让你轻松设计出rest风格的网站原创 2015-09-15 17:40:43 · 682 阅读 · 0 评论 -
Python iter
# iter(object)s=iter("abcd")for i in s: print i,# iter(function,value)返回一个列表直至function return valueimport randomdef getrand(): return random.randint(1,100)for i in iter(getrand,50): pr转载 2015-09-07 22:31:15 · 361 阅读 · 0 评论 -
Python ConfigParser
test.conf[option]item1=121item2=122import ConfigParsercs=ConfigParser.ConfigParser()cs.read("test.conf")print cs.sections()print cs.options("option")print cs.items("option")print cs.get("option转载 2015-09-13 00:37:21 · 299 阅读 · 0 评论 -
Python os.system
import osos.system("ls")转载 2015-09-06 22:50:16 · 469 阅读 · 0 评论 -
Python sys.argv
sys.argv 用于获取命令行参数test.pyimport sysfor i in sys.argv: print i,@ python test.py testR: test.py test转载 2015-09-10 20:18:29 · 354 阅读 · 0 评论 -
Django ajax
url.pyfrom django.conf.urls import urlfrom views import ajax_dealurlpatterns=[url(r'^/ajax/$',ajax_deal)]views.pyfrom django.http import HttpResponsedef ajax_deal(request): name=request.GET['原创 2015-09-03 13:56:57 · 329 阅读 · 0 评论 -
Python 查看网页编码方式
import chardet,urllibdata=urllib.urlopen("http://www.baidu.com")chardt=chardet.detect(data)print chardt["encoding"]转载 2015-09-09 21:51:52 · 567 阅读 · 0 评论 -
Python urllib
# coding=utf-8import urllib,jsondef getCityWeather(cityId): url="http://www.weather.com.cn/data/sk/"+str(cityId) stdout=urllib.urlopen(url) weatherInfo=stdout.read().decode("utf-8") j转载 2015-09-08 22:00:33 · 526 阅读 · 0 评论 -
Python urllib
import urllibhtml=urllib.urlopen("www.baidu.com").read()f=urllib.urlretrieve("www.baidu.com","c:/mysite/1.html")转载 2015-09-04 11:41:35 · 265 阅读 · 0 评论 -
Python @property
class A: @property def name(self): return self.name @name.setter def name(self,name): //可以加判断name是否是合法的 self.name=name转载 2015-08-29 22:19:25 · 297 阅读 · 0 评论 -
Python 单例模式
class Single(object): def __new__(cls,*args,**kw): if not hasattr(cls,"_instance"): cls._instance=super(Single,cls).__new__(cls,*args,**kw) return cls._instanceclass MyC转载 2015-08-29 09:57:32 · 249 阅读 · 0 评论 -
Django 静态文件配置
Django 的静态文件假如都要加一个{{static_url}}显得很麻烦。解决方案:修改url.pypathA=os.path.join(os.path.dirname(__file__),"static")url(r'^app/static/?P<path>.*$','django.views.static.serve',{'document_root':pathA} //?P表明后转载 2015-08-26 14:42:55 · 438 阅读 · 0 评论 -
Python操作MySQL
import MySQLdbcon=MySQLdb.connect(host="",username="",passwd="",db="",port="")cur=con.cursor()sql="update user set password='' where name='' "try: cur.execute(sql)except: con.rollback()co转载 2015-08-24 11:57:57 · 278 阅读 · 0 评论 -
文章标题
import MySQLdbclass Mysql_api: def __init__(self,database_name,username="root",password="******"): try: self.con=MySQLdb.connect(host="localhost",user=username,passwd=password,原创 2015-10-14 20:02:22 · 322 阅读 · 0 评论