
python
文章平均质量分 63
Sugeei
80,双鱼
展开
-
Python 3.4 - urllib.request 学习爬虫爬网页(一)
比如爬baidu.com, 在python 3.4 中应该这么写 import urllib.requestdef getHtml(url): page = urllib.request.urlopen(url) html = page.read() return htmlhtml = getHtml("http://baidu.com")print (html原创 2015-08-27 15:02:30 · 2052 阅读 · 0 评论 -
Python之闭包应用小游戏Tic Tac Toe
来自网易云课堂http://study.163.com/course/courseLearn.htm?courseId=1000035#/learn/video?lessonId=1252115&courseId=1000035‘用python做些事’-井字棋学习这个小程序的时候想到playerMove() 函数正好可以用来练习闭包。于是做了一些改动。# 定义闭原创 2016-02-19 15:31:52 · 1131 阅读 · 0 评论 -
python之xml文件处理的例子-问题描述及解决方法
待解决问题描述:多个XML文件,具有相同的格式,如下:…………不同xml文件中的标签个数不同。有的50个,有的80个。 代码目标:提取test 标签的 name 属性值,将这些值保存到excel文件中,并为每个值加上日期。生成表格如下:F0001月6日原创 2016-02-14 11:11:06 · 1363 阅读 · 0 评论 -
Python之sax的ContentHandler类方法处理多行内容的情况
首先贴出一个对contentHandler类方法的介绍,参考自http://www.linuxidc.com/Linux/2015-01/111147.htmcharacters(content)方法调用时机 从行开始,遇到标签之前,存在字符,content的值为这些字符串。 从一个标签,遇到下一个标签之前, 存在字符,content的值为这些字符串。从一个标签,遇到行结束原创 2016-02-27 21:50:31 · 2671 阅读 · 0 评论 -
Python 2.7 解决写入文件的中文乱码问题
续:python之xml文件处理的例子-问题描述及解决方法从一个文件中读入中文字符再写入到另一个文件中,遇到中文乱码问题。学习到一个方法解决这个问题,分享如下。 环境: python 2.7 背景:待处理的xml文件中有中文字符,想要提取文件中的一部分指定字段写入到Excel文件中,实际写入的是一个CSV文件,以.csv为后缀,文件生成之后可以转换为Excel表格。原创 2016-04-13 19:09:32 · 17321 阅读 · 2 评论 -
python re.compile(?P<name>)
正则还可以这样匹配。。。geeksquiz 网站提供代码题,可用于自测一门语言的掌握情况,今天做python有了有趣的发现——原来正则还可以这样写>>>sentence = 'cats are fast'regex = re.compile('(?P\w+) (?P\w+) (?P\w+)')matched = re.search(regex, sentence)prin原创 2016-05-08 10:20:03 · 4986 阅读 · 0 评论 -
Python pip install
表示还是官方文档靠谱pip安装方法参考https://pip.pypa.io/en/stable/installing/原创 2016-06-08 22:52:09 · 558 阅读 · 0 评论 -
RobotFramework 入门
step 1 : 安装可以很简单。 python安装2.7版本,robotframework 仅支持2.7版本wxpython安装2.8版本,ride基于wxpython,仅支持2.8版本 接下来安装robotframework:从网上找了好几遍都没找到Robotframework-ride的安装包。从Pypi下载的source文件一开始不知道如何下手。最终好不容易找到一篇原创 2016-04-26 10:56:08 · 1097 阅读 · 0 评论 -
Python decorator @property
Python @propertyPython version 3.4 参考自下文http://blog.youkuaiyun.com/elevenqiao/article/details/6796770 Python 代码 1class A: pass Python Shell>>原创 2015-09-25 17:18:26 · 842 阅读 · 0 评论 -
python xlsxwriter vs openpyxl
xlsxwriter 实现将数据按某种指定的格式写入excel, openpyxl 则以某种格式将excel读入并做处理。 这两个工具都有比较讲解清晰的文档,十分易用。 也再次证明,学好英文走遍天下也不怕。终究很多文档还是看英文原版本来得靠谱。 - xlsxwriter - openpyxlxlsxwriter 设置表格格式从文档中可以很方便的查看函数的用法,还有demo。import原创 2016-07-15 15:15:44 · 4292 阅读 · 0 评论 -
Python之enumerate
# enumerate 返回一个可遍历对象中各元素的值及索引for i,j in enumerate('abc'): print i,j0 a1 b2 c# 重复值保留for i,j in enumerate('abca'): print i,j0 a1 b2 c3 a# 返回的第一个值是索引,第二个是值a = {j:i for i,j in enum原创 2016-02-18 10:48:56 · 483 阅读 · 0 评论 -
Python之闭包学习笔记
走棋子是一个很好的例子理解为什么用闭包。资料来自网易云课堂http://study.163.com/course/courseLearn.htm?courseId=1000035#/learn/video?lessonId=1252115&courseId=1000035假设需求是给定一颗在[0,0]位置的棋子,用户交互输入移动方向与步数,写一个函数记录棋子的位置变化。这个函数可以原创 2016-02-16 14:09:59 · 643 阅读 · 0 评论 -
Leetcode Algorithm No.268 Missing Number
Given an array containing n distinctnumbers taken from 0, 1, 2, ..., n, find the one that is missing fromthe array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should run原创 2015-11-01 17:55:59 · 542 阅读 · 0 评论 -
Leetcode Algorithm No.242 Valid Anagram
问题描述:Giventwo strings s and t, write a function to determineif t is an anagram of s.Forexample,s = "anagram", t = "nagaram",return true.s = "rat", t = "car", returnfalse.Note:You may assum原创 2015-09-08 10:14:55 · 840 阅读 · 0 评论 -
Leetcode Algorithm No.241 Different Ways to Add Parentheses
题目来自LeetcodeGiven a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.原创 2015-08-31 14:24:29 · 810 阅读 · 0 评论 -
Leetcode Algorithm No.241 Different Ways to Add Parentheses - 学高手写代码
方法一''' 跟着高手写python ''' import re'''This module provides regular expression matching operations similar to those found in Perl. For \D in module reMatches any character which is not a Unicode原创 2015-09-10 22:04:39 · 629 阅读 · 0 评论 -
Python 初识Pandas- Python Data Analysis Library
Python 初识Pandas- Python Data Analysis Library学习资料来自于1. Coursera 《用Python 玩转数据》 https://www.coursera.org/learn/hipython 2. 网站:http://pandas.pydata.org/ Pandas Series>>>原创 2015-09-28 17:45:37 · 3446 阅读 · 0 评论 -
Leetcode Algorithm No.2 Add Two Numbers
You are given two linked lists representing two non-negativenumbers. Thedigits are stored in reverse order and each of their nodes contain a singledigit. Add the two numbers and return it as a linke原创 2015-09-13 15:32:30 · 505 阅读 · 0 评论 -
Leetcode Algorithm No.260 Single Number III
260 Single Number IIIGivenan array of numbers nums, in which exactly two elements appear onlyonce and all the other elements appear exactly twice. Find the two elementsthat appear only once.Fore原创 2015-09-15 15:15:20 · 875 阅读 · 0 评论 -
Python 初识GUI
学习资料来自于1. Coursera 《用Python玩转数据》 https://www.coursera.org/learn/hipython 2. Coursera 《Python交互程序设计入门》https://www.coursera.org/course/interactivepython1 Python面向对象定义一个小狗类原创 2015-10-01 11:36:05 · 745 阅读 · 0 评论 -
Python Regular Expression
Regular expression in Python ^Matches the beginning of a line$Matches the end of the line.Matches any character \smatches whitespace原创 2015-09-14 19:53:14 · 671 阅读 · 0 评论 -
Python 的set 类型及其copy方法
Python 的set 类型用法>>> set('you need python.'){' ', 'd', 'e', 'o', 'h', 'p', '.', 'n', 'y', 'u', 't'} >>> type(set('you need python.')) >>> sorted(set('you need原创 2015-09-24 17:54:53 · 1088 阅读 · 0 评论