python
文章平均质量分 61
fengyufengzi
这个作者很懒,什么都没留下…
展开
-
python 利用smtp发送邮件,html格式
def send_mail(to_list, sub, context):#sentmail to the maillist ''' to_list: 发送给谁 sub: 主题 context: 内容 send_mail("xxx@126.com","sub","context") ''' #print 'test begins原创 2014-09-03 14:47:59 · 591 阅读 · 0 评论 -
Python模块包中__init__.py文件的作用
转载自:http://hi.baidu.com/tjuer/item/ba37ac4ce7482a0f6dc2f08b 模块包:包通常总是一个目录,目录下为首的一个文件便是 __init__.py。然后是一些模块文件和子目录,假如子目录中也有 __init__.py 那么它就是这个包的子包了。差不多就像这样吧:Package1/ __init__.py Module1.py原创 2014-09-03 14:48:30 · 237 阅读 · 0 评论 -
python 编码问题
有时候需要将命令行或者网页上的或者文件中的内容读取出来做些处理,这个时候可能你发现读取出来的内容是其他的编码方式,如\x20等。处理思路如下:下载chardet模块,安装。利用chardet模块检测读取出来的str是什么编码格式的,如‘UTF-8'或者’GB2312‘等。>>> import chardet>>> chardet.detect(a){'confidenc原创 2014-09-03 14:47:17 · 475 阅读 · 0 评论 -
python list去重的方法
转载于:http://yxmhero1989.blog.163.com/blog/static/112157956201381443244790/Python很简洁 我们喜欢简单有效的代码 一.{}.fromkeys(list).keys()list2 = {}.fromkeys(list1).keys()二.setlist2 = list(set(list1)原创 2014-09-03 14:48:22 · 406 阅读 · 0 评论 -
python urllib2的proxyhandler
1. 再a方法中新建了个opener,使用了代理: proxydict = {} proxydict['http'] = "http://%s:%s"%(ip,port) #print proxydict proxy_handler = urllib2.ProxyHandler(proxydict) opener = urllib2.build_原创 2014-09-03 14:48:36 · 986 阅读 · 0 评论 -
python optparse模块
为了从更快的的使用这个模块,我们会省略一些东西,开始吧。1. 加载模块from optparse import OptionParser2. 实例化OptionParse,可以理解为表明useage和version:如parser = OptionParser(usage="usage: %prog [options] ",原创 2014-09-03 14:47:44 · 353 阅读 · 0 评论 -
python 利用imap接收邮件,并保存附件
def SaveAttachImap():# login the imap server ,retrive the new mails ,and download the attachments. M = imaplib.IMAP4(mail_host,mail_port) #print M M.login(mail_user,mail_pass) M.select('I原创 2014-09-03 14:48:01 · 3425 阅读 · 0 评论 -
python 利用pop3接收邮件并保存附件
def SaveAttach():# login the pop3 server ,retrive the new mails ,and download the attachments dstdir =dirname+str(time.ctime(time.time()))+'.zip' print 'starts' pp = poplib.POP3_SSL(ma原创 2014-09-03 14:48:03 · 4482 阅读 · 0 评论 -
python url编码,解码
>>> urllib.unquote('%E4%B8%BD%E6%B1%9F') >>> data'\xe4\xb8\xbd\xe6\xb1\x9f'>>> urllib.quote(data)原创 2014-09-03 14:47:53 · 308 阅读 · 0 评论 -
python 时间处理(time和datetime介绍)
python的有关时间的有哪几种呢?今天我们介绍两个:time和datetime time模块提供各种操作时间的函数 datetime模块定义了下面这几个类:datetime.date:表示日期的类。常用的属性有year, month, day;datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond;date原创 2014-09-03 14:47:40 · 429 阅读 · 0 评论 -
python logging
参考:http://www.cnblogs.com/dkblog/archive/2011/08/26/2155018.html通过logging.config模块配置日志#logger.conf###############################################[loggers] #有哪些日志原创 2014-09-03 14:47:57 · 239 阅读 · 0 评论 -
python 模拟浏览器
想用python模拟浏览器访问web的方法测试些东西,有哪几种方法呢?一类:单纯的访问web,不解析其js,css等。1. urllib2#-*- coding:utf-8 -*import urllib2def Furllib2(ip,port,url,timeout): proxydict = {} proxydict['http'] = "ht原创 2014-09-03 14:48:26 · 859 阅读 · 0 评论 -
python各种类型转换-int,str,char,float,ord,hex,oct等
int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到一个浮点数 complex(real [,imag ]) 创建一个复数 str(x ) 将对象 x 转换为字符串 repr(x )原创 2014-09-03 14:47:34 · 446 阅读 · 0 评论 -
python mysql中查询数据,结果中文显示乱码
利用python写程序从mysql中读取数据写入excel中,结果发现中文显示乱码。网上搜索了下方法: Python文件设置编码 utf-8 (文件前面加上 #encoding=utf-8), 同时文件保存的格式也应该是utf8 MySQL数据库charset=utf-8 ,数据库的编码必须是utf8 python连接MySQL时加上编码参数 conn = MySQLdb.C原创 2014-09-03 14:47:08 · 760 阅读 · 0 评论 -
python 编码问题(二)
>>> a = '中文'>>> chardet.detect(a){'confidence': 0.7525, 'encoding': 'utf-8'}>>> b = a.decode('utf-8')>>> bu'\u4e2d\u6587'>>> c = b.encode('gb2312')>>> c'\xd6\xd0\xce\xc4'>>> d = b.en原创 2014-09-03 14:47:29 · 452 阅读 · 0 评论 -
python os.stat() 和 stat模块详解
stat 系统调用时用来返回相关文件的系统状态信息的。首先我们看一下stat中有哪些属性:>>> import os>>> print os.stat("/root/python/zip.py")(33188, 2033080, 26626L, 1, 0, 0, 864, 1297653596, 1275528102, 1292892895)>>> print os.sta原创 2014-09-03 14:47:36 · 437 阅读 · 0 评论 -
python 字符串格式化 输出
1. 需要输出3列,为了输出好看,需要制定每一列的宽度:‘%6.2f’ % 1.235# 长度为6,保留2为小数 print '{0:20} {1:<20} {1:<20}\r\n'.format(ip.strip(),jsondata['isv'],jsondata['isp'])#20表示长度为20,不足的用空格补充,<代表左对齐原创 2014-09-03 14:47:49 · 339 阅读 · 0 评论 -
利用python 获取 windows 组策略
工作中有时候会有这种需求:1. 自动配置组策略的安全基线,这个东西不用你自己写了,微软有这个工具,Microsoft Security Compliance Manager,你可以在下面的地址去下载和学习使用。 technet.microsoft.com/library/cc677002.aspx2. 但是有时候你可能需要自动化的获取服务器上的某些信息,如cpu啊,disk等,以及组原创 2014-09-03 14:47:21 · 2725 阅读 · 0 评论