- 博客(20)
- 收藏
- 关注
原创 文章标题
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
333
原创 Javascript 闭包中的this
//闭包能获得闭包外函数的变量var name="win";(function(){ var name="fun"; alert(name); return function(){ alert(name); } })()();//闭包中this的归属var obj={name:"ob",fun1:function(){ return function
2015-10-09 17:20:14
367
原创 Python json.dumps
import jsons={}s["required"]="get"b=[]b.append("i")json.dumps(b)json.dumps(s)
2015-09-23 10:30:51
538
原创 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
706
转载 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
398
原创 Python Django rest_framework
Rest—面向资源的架构其实Django默认的Admin就是一个很好地rest架构风格的设计。 /poll/admin/user/1 =>第一个user对象(id作为最后一个url的分界。)rest_framework一个比较好的框架可以让你轻松设计出rest风格的网站
2015-09-15 17:40:43
688
转载 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
310
转载 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
366
转载 Python 查看网页编码方式
import chardet,urllibdata=urllib.urlopen("http://www.baidu.com")chardt=chardet.detect(data)print chardt["encoding"]
2015-09-09 21:51:52
579
转载 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
532
转载 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
369
转载 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
272
原创 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
338
转载 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
305
转载 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
255
转载 Tomcat 配置
1.新建Tomcat_Home: XXX/Tomcat2.CLASSPATH加入一句%Tomcat_Home%\lib\servlet-api.jar;这样import javax.XX就不会报错了。如果是把java项目部署到服务器,只需在Tomcat配置文件的 host节点内加入:<Context path="/hello" docBase="C:/Users/XX/IdeaProjects/fi
2015-08-26 22:04:18
296
转载 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
450
转载 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
330
转载 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
286
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人