
python
小沫_jie
这个作者很懒,什么都没留下…
展开
-
python中range()函数的用法--转载
详细记录python的range()函数用法使用python的人都知道range()函数很方便,今天再用到他的时候发现了很多以前看到过但是忘记的细节。这里记录一下range(),复习下list的slide,最后分析一个好玩儿的冒泡程序。这里记录一下:>>> range(1,5) #代表从1到5(不包含5)[1, 2, 3, 4]>>> range(1,5,2) #代表从1到5,间隔2(不包含5)转载 2016-10-15 15:10:40 · 1820 阅读 · 0 评论 -
windows下安装python及其配置
1、下载安装 Python python-2.7.2.msi http://www.python.org/download/ 如下载 Python 2.7.2,安装目录为 C:\Python272、添加环境变量 path = C:\Python27 此步骤可实现在命令行下,不用进入 Python 目录即可执行 python.exe3、下载 setuptools 注意对应 Python 的转载 2016-10-31 19:48:00 · 264 阅读 · 0 评论 -
python--爬虫1
1.基础方法url = “http://www.baidu.com”html = urllib.urlopen(url) #打开网页,获取类对象文件content = html.read() #读网页内容print html.getcode()#获取网页状态码 404网页不存在 200可以正常访 问 301重定向 403禁止访问#print html原创 2016-10-19 09:43:25 · 390 阅读 · 0 评论 -
Cousera-Using python to access web data(第2~4周笔记)
第二周: 正则表达式 http://www.cnblogs.com/moonache/p/5110322.html 第三周: Networks and Sockets http://www.cnblogs.com/moonache/p/5112060.html 第四周:Programs that Surf the Web http://www.cnblogs.com/moonache/原创 2016-10-31 20:28:48 · 9952 阅读 · 1 评论 -
python - BeautifulSoup中的find()和findAll()
内容取自《python 网络数据采集》原创 2016-11-30 16:50:58 · 10388 阅读 · 2 评论 -
Python报错:ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that ca
ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch原创 2016-12-02 10:37:54 · 577 阅读 · 0 评论 -
scrapy安装配置教程
http://cuiqingcai.com/912.html http://blog.youkuaiyun.com/pleasecallmewhy/article/details/19354723 http://blog.youkuaiyun.com/wukaibo1986/article/details/8167590原创 2016-11-22 16:50:52 · 462 阅读 · 0 评论 -
Python读取文件夹下的所有文件
转自:http://blog.youkuaiyun.com/lzgs_4/article/details/50371030os.listdir(path)是得到在path路径下所以文件的名称列表。open(path)是打开某个文件。iter是python的迭代器。 所以读取某文件夹下的所有文件如下:import os path = "D:/Python34/news" #文件夹目录 files=转载 2017-02-09 15:18:09 · 7148 阅读 · 0 评论 -
Python的替换函数——strip(),replace()和re.sub()
在Python中常用的三个“替换”函数是strip(),replace()和re.sub(),下面来讲讲这三个函数的用法。一.replace()基本用法:对象.replace(rgExp,replaceText,max)其中,rgExp和replaceText是必须要有的,max是可选的参数,可以不加。rgExp是指正则表达式模式或可用标志的正则表达式对象,也可以是 String 对象或文字转载 2017-07-27 14:47:34 · 855 阅读 · 0 评论 -
Python--正则式
原文地址:http://blog.youkuaiyun.com/whycadi/article/details/2011046正则表达式:并不是python特有的,它是一种小型的、高度专业化的编程语言1. Python正则式的基本用法1.1基本规则1.2重复1.2.1最小匹配与精确匹配1.3前向界定与后向界定1.4组的基本知识2. re模块的基本函数2.1使用com转载 2016-10-20 14:51:01 · 789 阅读 · 0 评论 -
pthon--字符串拼接
原文地址:http://blog.youkuaiyun.com/henulwj/article/details/48719973 Python字符串拼接在Python的实际开发中,很多都需要用到字符串拼接,Python中字符串拼接有很多,今天总结一下:用+符号拼接用%符号拼接用join()方法拼接用format()方法拼接用string模块中的Template对象 如果还有其他方法,欢迎补充。转载 2016-10-20 15:04:23 · 468 阅读 · 0 评论 -
python--文件操作
1.文件打开与关闭1.1打开文件a. 使用open(filename)函数打开文件from sys import argvscript, filename = argvtxt = open(filename)#代开后使用read函数读取文件内容输出print txt.read()b.再次运行 python 在命令行下使用 open 打开一个文件,这种 open 和 read 的方法也值得一学原创 2016-10-13 13:48:32 · 799 阅读 · 0 评论 -
python--if条件判断
if 语句例子:people = 20cats = 30dogs = 15if people < cats: print "Too many cats! The world is doomed!"if people > cats: print "Not many cats! The world is saved!"#if - elif - else if cars原创 2016-10-15 14:24:23 · 3838 阅读 · 0 评论 -
python--函数
1.函数的定义# this one is like your scripts with argvdef print_two(*args): arg1, arg2 = args print "arg1: %r, arg2: %r" % (arg1, arg2)# ok, that *args is actually pointless, we can just do this原创 2016-10-14 10:11:30 · 493 阅读 · 0 评论 -
Python--模块、类、对象、继承、合成
1. 模块模块和字典差不多,它的一些属性:1.模组是包含函数和变量的 Python 文件。2.你可以 import 这个文件。3.然后你可以使用 ‘.’ 操作符访问到模组中的函数和变量。假如说有一个模块名字叫 mystuff.py 并且在里边放了个叫做 apple 的函数,就像这样:# this goes in mystuff.pydef apple(原创 2016-10-15 18:44:15 · 2759 阅读 · 0 评论 -
python--循环、列表、字典、元组
1.for-loop和列表在开始使用 for 循环之前,你需要在某个位置存放循环的结果。最好的方法是使用列表(list),顾名思义,它就是一个按顺序存放东西的容器。如 何创建列表: hairs = [‘brown’, ‘blond’, ‘red’] eyes = [‘brown’, ‘blue’, ‘green’] weights = [1, 2, 3, 4]the_count = [1,原创 2016-10-15 15:07:01 · 853 阅读 · 0 评论 -
python - 中文问题
# -*- coding: UTF-8 -*-#coding:utf-8中文问题: Python内部所有编码时Unicode 是一种中转码 中文是gbk 正常输出是utf-8 //代码中使用了# -- coding: UTF-8 --乱码–>unicode中转码–>我们需要的编码格式decode() –> unicode –>encode我们需要的编码例子: print cont原创 2016-10-18 23:10:10 · 314 阅读 · 0 评论 -
Python-第三方库requests详解
Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求。Requests 的哲学是以 PEP 20 的习语为中心开发的,所以它比 urllib 更加 Pythoner。更重要的一点是它支持 Python3 哦!Beautiful is bett转载 2016-10-19 15:57:38 · 540 阅读 · 0 评论 -
解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
原文地址:http://wangye.org/blog/archives/629/转载 2016-10-19 22:51:52 · 282 阅读 · 0 评论 -
汉诺塔问题-python
汉诺塔:原创 2018-02-25 14:36:40 · 210 阅读 · 0 评论