《用Python玩转数据》第2周学习笔记(Part1)
来源:互联网 发布:json测试工具 编辑:程序博客网 时间:2024/05/29 04:57
1、Python之文件操作:http://blog.chinaunix.net/uid-26602509-id-3503138.html
2、正则表达式教程:
http://deerchao.net/tutorials/regex/regex.htm
http://www.java3z.com/cwbwebhome/article/article8/Regex/Java.Regex.Tutorial.html
http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html
如果要处理数据,正则表达式是必须要熟练掌握的。现在两眼一抹黑,看不懂下面的代码是如何通过正则表达式获取数据的:
import urllibimport redStr = urllib.urlopen('http://finance.yahoo.com/q/cp?s=%5EDJI+Components').read()m = re.findall('<tr><td class=\"yfnc_tabledata1\"><b><a href=\".*?\">\(.*?)</a></b></td><td class=\"yfnc_tabledata1\">(.*?)</td>.*?<b>(.*?)</b>.*?</tr>', dStr)if m: print m print '\n' print len(m)else: print 'not match'
暂停第2周学习,先把正则表达式搞定。
3、编程小练习:
创建一个文件src.txt,文件内容为:
How many seas must a white dove sail
Before she sleeps in the sand
将src.txt的内容复制到文件dest.txt中,并在dest.txt文件头部添加另两行字符串,添加后dest.txt文件中的内容为:
How many roads must a man walk down
Before they call him a man
How many seas must a white dove sail
Before she sleeps in the sand
f1 = open(r'D:\src.txt', 'w+')f1.writelines('How many seas must a white dove sail\nBefore she sleeps in the sand\n')f1.seek(0, 0)f2 = open(r'D:\dest.txt', 'w')f2.writelines('How many roads must a man walk down\n')f2.writelines('Before they call him a man\n')words = f1.readlines()for w in words: f2.writelines(w)f1.close()f2.close()
0 0
- 《用Python玩转数据》第2周学习笔记(Part1)
- 《用Python玩转数据》学习笔记第3周Part1
- 《用Python玩转数据》学习笔记第4周Part1
- 《用Python玩转数据》学习笔记第2周(Part2)
- 《用Python玩转数据》第1周学习笔记(Part 1)
- 《用Python玩转数据》第1周学习笔记(Part2)
- 《用Python玩转数据》学习笔记第3周Part2
- 用Python玩转数据第一周学习笔记のPython基础
- MOOC用Python玩转数据笔记 2
- Python玩转数据分析学习笔记-01基础
- Python玩转数据分析学习笔记-02语法
- Python玩转数据分析学习笔记-03数据获取
- Python玩转数据分析学习笔记-04字典相关
- Python玩转数据分析学习笔记-05数据
- 南京大学MOOC用python玩转数据课程笔记
- 《用Python玩转数据》Week5, Part 2
- 用python玩转数据|基本语法
- 《用python玩转数据》1
- 各个raid对比:性能和运行速度和读写方面
- 杭电ACM2159(二维背包)
- Cohen-Sutherland线段裁剪算法
- 学习ectouch之文件结构
- AngularJs开发实践第一天(1)
- 《用Python玩转数据》第2周学习笔记(Part1)
- jQuery实现页面详情展开收起
- Log4j.properties文件配置详解及模板
- SVN 多项目配置 (shell 一键配置)
- Android仿Iphone通知角标的实现
- Android:详情界面左右滑动看更多,ViewPager动态添加Fragment,仿51job详情界面
- #Hostapd之main函数(2)
- 2015 Objective-C 新特性
- 理解RESTful架构