
Python学习
imwhatiam
这个作者很懒,什么都没留下…
展开
-
Python学习:遍历时不要对遍历对象(此处是列表)进行删除操作
while Pool: time.sleep(1) #此处有关于enumrrate()函数的用法:笔记1 for index,the_thread in enumerate(Pool): #线程还在运行,就让它继续运行,不再运行了就在线程池Pool中删掉此线程 if the_thread.isAlive(): cont原创 2013-11-04 10:40:51 · 560 阅读 · 0 评论 -
Python学习:logging模块学习
曲折1:开始把保存测试代码的文件命名为logging.py,运行时候提示:'module' object has no attribute 'basicConfig'网上查到关于此问题的解决办法:You've got another module called logging on the python path; probably a file logging.py in the sam原创 2013-12-21 13:43:33 · 1972 阅读 · 0 评论 -
Python实践:多线程
关于多线程基础的操作和处理,本想自己整理一下,但是发现自己整理也就是把别人写的抄过来,还不如直接抄过来呢,哈哈。只放上两个链接吧:http://blog.youkuaiyun.com/jgood/article/details/4299476http://blog.youkuaiyun.com/JGood/article/details/4305604#comments这两篇文章的代码自己都实践过,也转载 2013-10-31 11:57:30 · 964 阅读 · 0 评论 -
Python学习:enumrrate()函数的用法
#coding:utf-8import stringlist_1 = ['a','b','wo','hh','time',3,67,8]for index, value in enumerate(list_1): print index, values = string.ascii_lowercasee = enumerate(s)print sprint epri原创 2013-11-04 10:22:26 · 673 阅读 · 0 评论 -
Python学习资料整理
写了一些博客,有自己原创的也有转载的,整理了一下放在这里,方便以后查找,以后还会不断更新:Python学习笔记1. 基础知识1. 解析变量赋值及数据存放地址:(http://blog.youkuaiyun.com/imwhatiam/article/details/17458215)2. 遍历时不要对遍历对象(此处是列表)进行删除操作:(http://blog.youkuaiyun.com/im原创 2013-12-21 14:11:05 · 452 阅读 · 0 评论 -
Python学习:闭包和装饰器
基础的说明,转自:http://www.cnblogs.com/livingintruth/p/3305697.html1,闭包(closure)闭包是Python所支持的一种特性,它让在非global scope定义的函数可以引用其外围空间中的变量,这些外围空间中被引用的变量叫做这个函数的环境变量。环境变量和这个非全局函数一起构成了闭包。 1 def outer(x)转载 2013-12-21 13:35:53 · 741 阅读 · 0 评论 -
Python学习:正则表达式
下面是网上转来的一片文章,写的很全,等自己实际用到了,在更新自己的代码。转自:http://blog.youkuaiyun.com/pleasecallmewhy/article/details/8929576 [Python]网络爬虫(七):Python中的正则表达式教程分类: 爬虫 Python2013-05-15 13:29 3162人阅读 评论(0) 收原创 2013-10-22 22:39:08 · 694 阅读 · 0 评论 -
Python学习:Django
参考了:http://docs.30c.org/djangobook2/chapter01/MVC:模型,代码的定义&数据访问的方法;视图,用户接口;控制器,请求逻辑。各个组件松散组合,互不影响。——————————项目,是 Django 实例的一系列设置的集合,它包括数据库配置、Django 特定选项以及应用程序的特定设置。——————————startp转载 2013-12-19 10:54:33 · 231 阅读 · 0 评论 -
Python学习:排序相关
#coding:utf-8#-----根据字典的value来排序-----print '-----根据字典的value来排序-----'from operator import itemgettera = {"a":"4", "sss":"2", "ffdf":'5', "ffff2":'3'}sort_a = sorted(a.items(), key = itemgetter(1原创 2013-12-26 00:38:47 · 429 阅读 · 0 评论 -
Python学习:遍历目录,查找特定文件,用os.walk()方法
这是代码#coding:utf-8#-----遍历目录,查找特定文件,用os.walk()方法-----import osFileList = []rootdir = "/home/lian/python"for root, subFolders, files in os.walk(rootdir): #排除特定的子目录 if 'done' in subFold转载 2013-12-26 22:36:13 · 5115 阅读 · 0 评论 -
Python学习:局部变量、全局变量、默认参数、关键参数
我是在这里学习的: http://woodpecker.org.cn/abyteofpython_cn/chinese/pr01.html#s011、下面是一个在多个物理行中写一个逻辑行的例子。它被称为明确的行连接。s = 'This is a string.\ This continues the string.'print s输出为>>> This原创 2013-10-18 22:47:42 · 524 阅读 · 0 评论 -
Python学习:格式化输出
输出语句 print 函数#输出小数点后3位(四舍五入),共6位。#‘6’共输出6位数;‘3’小数点后精度为3print (format(12.34567, '6.3f'))print (format(12.34567, '6.9f'))#共输出6位,不够输出左边补齐print (format(12.34567, '6.0f'))print (format(0.34567转载 2013-12-21 01:49:13 · 699 阅读 · 0 评论 -
Python学习:Python基础教程(第二版)学习笔记—SQlite
#encoding:utf-8#import sqlite3###def convert(value):## try:## if value.startswith("~"):## return value.strip("~")## if not value:## value = "0"##原创 2013-12-16 22:04:29 · 132 阅读 · 0 评论 -
Python学习:Python基础教程(第二版)学习笔记—异常
#coding:utf-8while True: try: x = input("the first num:") y = input("the second num:") value = x/y print "x/y is :", value #在except子句后面忽略所有的异常类,可以捕捉所有的异常原创 2013-12-16 14:32:16 · 432 阅读 · 0 评论 -
Python学习:Python基础教程(第二版)学习笔记—SQlite
encoding:utf-8import sqlite3#def convert(value):# try:# if value.startswith("~"):# return value.strip("~")# if not value:# value = "0"# return f原创 2013-12-16 22:06:49 · 1343 阅读 · 0 评论 -
Python实践:Requests模块
参考:http://cn.python-requests.org/en/latest/user/quickstart.html#id8发送请求使用Requests发送网络请求非常简单。一开始要导入Requests模块:>>> import requests然后,尝试获取某个网页。本例子中,我们来获取Github的公共时间线>>> r =转载 2013-12-20 21:46:29 · 6570 阅读 · 0 评论 -
Python实践:HTMLParser模块
HTMLParser是python用来解析html的模块。它可以分析出html里面的标签、数据等等,是一种处理html的简便途径。HTMLParser采用的是一种事件驱动的模式,当HTMLParser找到一个特定的标记时,它会去调用一个用户定义的函数,以此来通知程序处理。它主要的用户回调函数的命名都是以handler_开头的,都是HTMLParser的成员函数。当我们使用时,就从HTMLParse转载 2013-12-20 21:45:27 · 789 阅读 · 0 评论 -
Python学习:xrange()的用法
转自:http://ciniao.me/article.php?id=17range 函数说明:range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列。range示例: >>> range(5) [0, 1, 2, 3, 4] >>> range(1,5) [1, 2, 3, 4] >>> ra转载 2013-12-21 00:38:14 · 505 阅读 · 0 评论 -
Python学习:2013年PyCon北京大会 & Python 隐藏的玄机
Python 隐藏的玄机的PPT在这里:http://vdisk.weibo.com/s/annw3IyYgZ0DA自己的学习笔记如下(自己实现了PPT中的程序,也理解了作者要表达的意思,这里只写一些之前没用过的新知识点):对象与引用-列表的使用问题-取奇数列1、说明了一个注意事项:遍历时不要对遍历对象(此处是列表)进行删除操作(http://blog.youkuaiyun.com/imwhati原创 2013-12-21 00:21:30 · 120 阅读 · 0 评论 -
Python学习:切片的使用
字符串切片、逆序str = 'abcbefghijklmn'print strstr1 = str[0:9]print str1str2 = str[-9:-1]print str2str2 = str[-9:]print str2str3 = str[0:9:2]print str3str4 = str[-1:-9:-2]print str4str4 =转载 2013-12-21 01:04:18 · 413 阅读 · 0 评论 -
Python学习:解析变量赋值及数据存放地址
Python会将数值如1、2、3、4预先存放在固定地址的内存中,在将数值赋值给变量时,并不给变量申请内存空间,只是给变量一个内存地址的指向(类似C的指针),变量变化时,也只改动变量的指向,如:[python] view plaincopyx = 12 y = 13 print x, id(x) print y, id(y)原创 2013-12-21 00:46:49 · 805 阅读 · 0 评论 -
Python学习:MySQL
先放上一段代码#coding:utf-8import MySQLdb as mdbdef mysql_connect(): try: ''' conn = MySQLdb.Connect(host='localhost', user='root', passwd='root',\ db='python',charset='utf8转载 2013-12-26 22:31:07 · 670 阅读 · 0 评论