随笔分类 -  python基础

摘要:1.源代码connection=MySQLdb.connect( host="thehost",user="theuser", passwd="thepassword",db="thedb")cursor=connection.cursor()cursor.execute(query)f... 阅读全文
posted @ 2014-11-17 14:58 jianhong 阅读(304) 评论(0) 推荐(0) 编辑
摘要:1.smtplib模块的使用 smtplib库用来发送邮件。需要用到的函数如下:连接到SMTP服务器,参数为SMTP主机和端口: SMTP.connect([host[,port]]) 登录SMTP服务器,参数为邮箱用户名和密码: SMTP.login(user,password) 发送邮件。msg... 阅读全文
posted @ 2014-10-09 18:28 jianhong 阅读(1082) 评论(1) 推荐(1) 编辑
摘要:1.smtplib模块的使用 smtplib库用来发送邮件。需要用到的函数如下:连接到SMTP服务器,参数为SMTP主机和端口: SMTP.connect([host[,port]]) 登录SMTP服务器,参数为邮箱用户名和密码: SMTP.login(user,password) 发送邮件。msg... 阅读全文
posted @ 2014-10-09 18:28 jianhong 阅读(457) 评论(0) 推荐(0) 编辑
摘要:脚本:#!/usr/bin/pythondict={"a":"apple","b":"banana","o":"orange"}print"##########dict######################"foriindict:print"dict[%s]="%i,dict[i]print"... 阅读全文
posted @ 2014-10-08 17:13 jianhong 阅读(144) 评论(0) 推荐(0) 编辑
摘要:脚本:#!/usr/bin/pythondict={"a":"apple","b":"banana","o":"orange"}print"##########dict######################"foriindict:print"dict[%s]="%i,dict[i]print"... 阅读全文
posted @ 2014-10-08 17:13 jianhong 阅读(141) 评论(0) 推荐(0) 编辑
摘要:脚本:#!/usr/bin/pythondict={"a":"apple","b":"banana","o":"orange"}print"##########dict######################"foriindict:print"dict[%s]="%i,dict[i]print"... 阅读全文
posted @ 2014-10-08 17:13 jianhong 阅读(144) 评论(0) 推荐(0) 编辑
摘要:当函数的参数不确定时,可以使用*args 和**kwargs,*args 没有key值,**kwargs有key值。还是直接来代码吧,废话少说[python] view plaincopyprint?deffun_var_args(farg,*args):print"arg:",fargforval... 阅读全文
posted @ 2014-10-04 23:34 jianhong 阅读(2047) 评论(0) 推荐(0) 编辑
摘要:sort命令是帮我们依据不同的数据类型进行排序,其语法及常用参数格式: sort [-bcfMnrtk][源文件][-o 输出文件] 补充说明:sort可针对文本文件的内容,以行为单位来排序。参 数:-b忽略每行前面开始出的空格字符。-c检查文件是否已经按照顺序排序。-f排序时,忽略大小写字母。... 阅读全文
posted @ 2014-09-26 11:52 jianhong 阅读(278) 评论(0) 推荐(0) 编辑
摘要:Python中的ftplib模块Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件FTP的工作流程及基本操作可参考协议RFC959ftp登陆连接from ftplib import FTP #加载ftp模块ftp=FTP() #设置... 阅读全文
posted @ 2014-09-24 20:26 jianhong 阅读(233) 评论(0) 推荐(0) 编辑
摘要:[转]Python使用struct处理二进制(pack和unpack用法)Leave a reply转载自:http://www.cnblogs.com/gala/archive/2011/09/22/2184801.html这篇文章写的很好,所以无耻的转了。。有的时候需要用python处理二进制数... 阅读全文
posted @ 2014-09-24 18:24 jianhong 阅读(260) 评论(0) 推荐(0) 编辑
摘要:[转]Python使用struct处理二进制(pack和unpack用法)Leave a reply转载自:http://www.cnblogs.com/gala/archive/2011/09/22/2184801.html这篇文章写的很好,所以无耻的转了。。有的时候需要用python处理二进制数... 阅读全文
posted @ 2014-09-24 18:24 jianhong 阅读(262) 评论(0) 推荐(0) 编辑
摘要:[转]Python使用struct处理二进制(pack和unpack用法)Leave a reply转载自:http://www.cnblogs.com/gala/archive/2011/09/22/2184801.html这篇文章写的很好,所以无耻的转了。。有的时候需要用python处理二进制数... 阅读全文
posted @ 2014-09-24 18:24 jianhong 阅读(1081) 评论(0) 推荐(0) 编辑
摘要:From:http://www.iteye.com/topic/867446环境:linux一段执行时间很长的程序(用python做hive客户端执行mapreduce) 在linux后台执行,把结果输出到某文件:Python代码pythonxxx.py>log.log&遇到的问题,程序没报错,文件... 阅读全文
posted @ 2014-09-12 17:26 jianhong 阅读(595) 评论(0) 推荐(0) 编辑
摘要:From:http://www.iteye.com/topic/867446环境:linux一段执行时间很长的程序(用python做hive客户端执行mapreduce) 在linux后台执行,把结果输出到某文件:Python代码pythonxxx.py>log.log&遇到的问题,程序没报错,文件... 阅读全文
posted @ 2014-09-12 17:26 jianhong 阅读(348) 评论(0) 推荐(0) 编辑
摘要:python匹配中文的时候特别要注意的是匹配的正则字符串是否是Unicode格式的: import re source = "s2f程序员杂志一2d3程序员杂志二2d3程序员杂志三2d3程序员杂志四2d3" temp = source.decode('utf8') ... 阅读全文
posted @ 2014-09-12 10:46 jianhong 阅读(803) 评论(0) 推荐(0) 编辑
摘要:匹配中文:[\u4e00-\u9fa5]英文字母:[a-zA-Z]数字:[0-9]匹配中文,英文字母和数字及_:^[\u4e00-\u9fa5_a-zA-Z0-9]+$同时判断输入长度:[\u4e00-\u9fa5_a-zA-Z0-9_]{4,10}^[\w\u4E00-\u9FA5\uF900-\... 阅读全文
posted @ 2014-09-12 10:44 jianhong 阅读(290) 评论(0) 推荐(0) 编辑
摘要:一、问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1:代码段1:class A: def __init__(self): print "enter A" print "leave A" class B(A)... 阅读全文
posted @ 2014-08-18 00:02 jianhong 阅读(157) 评论(0) 推荐(0) 编辑
摘要:一、问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1:代码段1:class A: def __init__(self): print "enter A" print "leave A" class B(A)... 阅读全文
posted @ 2014-08-18 00:02 jianhong 阅读(126) 评论(0) 推荐(0) 编辑
摘要:一、问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1:代码段1:class A: def __init__(self): print "enter A" print "leave A" class B(A)... 阅读全文
posted @ 2014-08-18 00:02 jianhong 阅读(132) 评论(0) 推荐(0) 编辑
摘要:multiprocessing模块实现了对多进程编程的封装,让我们可以非常方便的使用多进程进行编程。它的使用方法非常类似threading模块。1.创建一个进程import multiprocessingdef worker(): """worker function""" print ... 阅读全文
posted @ 2014-07-10 13:15 jianhong 阅读(300) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示