
PYTHON
codingkid
这个作者很懒,什么都没留下…
展开
-
python知识积累(五)——编写模块
python中的Module是比较重要的概念。常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时,将事先写好的.py文件拷贝 到当前目录,或者是在sys.path中增加事先写好的.py文件所在的目录,然后import。这样的做法,对于少数文件是可行的,但转载 2011-08-14 19:45:10 · 906 阅读 · 0 评论 -
python知识积累(四)——文件操作
按行读取文件里的内容:try: f = file('test.txt','r')except: print "cannot find 'test.txt' " sys.exit(1)else: while True: line = f.readline()原创 2011-08-14 19:21:05 · 627 阅读 · 0 评论 -
python知识积累(三)字符串处理
用base64加/解密import base64a = "this is a test"b = base64.encodestring(a) # 对字符串编码print bprint base64.decodestring(b) # 对字符串解码分割和合并原创 2011-07-26 23:49:23 · 585 阅读 · 0 评论 -
python elementtree module parse XML tree(二)
import elementtree.ElementTree as etreemytree = etree.parse('test.xml')myroot = mytree.getroot()def func(ele,n):# global myroot for child in ele: child.set('deepth',str(n)) if chil原创 2011-07-13 18:18:05 · 1191 阅读 · 1 评论 -
python基础知识积累(一)数据类型转换
数据类型转换一、int函数能够 (1)把符合数学格式的数字型字符串转换成整数 (2)把浮点数转换成整数,但是只是简单的取整,而非四舍五入。 举例: 1 aa = int("124") #Correct 2 print "aa = ", aa #result=124 3 bb = int(123.45) #cor转载 2011-07-13 13:20:37 · 788 阅读 · 0 评论 -
python使用elementtree模块解析xml
import elementtree.ElementTree as etree#从字符串中获取root = etree.fromstring(xmlstr)#从xml文件流读入#遍历root下的子节点for child in root:#若child标签的值不为原创 2011-07-10 22:04:00 · 2925 阅读 · 0 评论 -
python连接mysql
#!/usr/bin/python#connect.py - connect to mysql serverimport sysimport MySQLdbtry: conn = MySQLdb.connect (db = "databasename"原创 2011-07-10 21:51:57 · 574 阅读 · 0 评论 -
利用python对csv文件的log解析
<br />之前很多时候遇到了需要解析log的情况。<br />写了个小脚本:<br />import csv#import log.csv and splited every elements by ';',then storage into rowlogreader=csv.reader(open('log.csv','rb'),delimiter=';')for lrow in logreader: print lrow#import log_format.csv for原创 2011-04-08 23:15:00 · 2541 阅读 · 0 评论 -
初学python后感
<br />之前就知道python的强大,只是还没系统的去学过。<br /><br />昨天晚上和今天上午几个小时时间把简明教程看了一遍,大致了解了一些python的语法和用法。<br /><br /><br />python是个脚本语言,动态执行的。<br /><br />python无处不在,从apache服务器,到pyunit单元测试,到桌面计算器,到图形化界面。<br /><br />python内置了三个强大的数据结构——列表list,元组tuple,字典dict。<br /><b原创 2011-04-08 15:49:00 · 1166 阅读 · 0 评论