2012年9月25日
摘要: 今天遇到一个错误:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3搜索网上找到一个解决办法(转载自 http://blog.sina.com.cn/s/blog_727b603701019pyl.html)异常: 'ascii' codec can't encode characters字符集的问题,在文件前加两句话:reload(sys)sys.setdefaultencoding( "utf-8" )完美解决,ok另外 当字符 阅读全文
posted @ 2012-09-25 15:08 mingaixin 阅读(22874) 评论(0) 推荐(0) 编辑
摘要: 1.Python内置了urlencode函数:urllib.urlencode()不幸的是,这个函数只能接收key-value pair格式的数据。即只针对dict的,urllib的文档中的例子呀: >>> import urllib >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/quer 阅读全文
posted @ 2012-09-25 15:05 mingaixin 阅读(32736) 评论(3) 推荐(1) 编辑
摘要: Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数。repr()与反引号操作符``做的是完全一样的事情;repr()返回的是一个对象的"官方"字符串表示(对python比较友好),绝大多数情况下可以通过求值运算(使用内建函数eval())重新得到该对象。即 obj= eval(repr(obj)),也有情况下,不能够通过eval()得到原来的对象,比如:>>> eval(`type(type)`)Traceback (most recent call last): File "<stdin>", 阅读全文
posted @ 2012-09-25 14:26 mingaixin 阅读(2918) 评论(0) 推荐(0) 编辑
摘要: 来源于 http://wuqinzhong.blog.163.com/blog/static/4522231200942225810117/#coding:utf-8#python 检测文件MD5值#python version 2.6import hashlibimport os#简单的测试一个字符串的MD5值src = 'teststring'print (hashlib.md5(src).hexdigest().upper())#hexdigest() 为十六进制值,digest()为二进制值#使用updatem0=hashlib.md5()m0.update(src)p 阅读全文
posted @ 2012-09-25 10:41 mingaixin 阅读(660) 评论(0) 推荐(0) 编辑
摘要: Python 编程中使用 time 模块可以让程序休眠,具体方法是time.sleep(秒数),其中"秒数"以秒为单位,可以是小数,0.1秒则代表休眠100毫秒。# 例1:循环输出休眠1秒import timei = 1while i <= 3: print i # 输出i i += 1 time.sleep(1) # 休眠1秒# 例1:循环输出休眠100毫秒import timei = 1while i <= 3: print i # 输出i i += 1 time.sleep(0.1) # 休眠0.1秒 阅读全文
posted @ 2012-09-25 10:39 mingaixin 阅读(1219) 评论(0) 推荐(0) 编辑