python2 urllib 笔记】的更多相关文章

python2 urllib 笔记 import urllib base='http://httpbin.org/' ip=base+'ip' r=urllib.urlopen(ip) print r.geturl() print r.read() #get get=base+"get" parms=urllib.urlencode({"name":"tom","age":18}) r=urllib.urlopen("…
python2  httplib 笔记 #coding=utf-8 ''' Created on 2014年9月25日 @author: cocoajin ''' import httplib,urllib base='httpbin.org' #不需要添加 "http://" con=httplib.HTTPConnection(base) ip = '/ip' con.request('GET',ip) re=con.getresponse() print re.getheader…
Item 2: Follow the PEP 8 Style Guide Naming Naming functions, variables, attributes lowercase_underscore protected instance attributes _leading_underscore private instance attributes __double_leading_underscore classes, exceptions CapitalizedWord mod…
一.Python 标准库概览 1.操作系统接口 os 模块提供了很多与操作系统交互的函数: >>> import os >>> os.getcwd() # Return the current working directory 'C:\\Python27' >>> os.chdir('/server/accesslogs') # Change current working directory >>> os.system('mkdi…
Infi-chu: http://www.cnblogs.com/Infi-chu/ Py2.x: Urllib库 Urllin2库 Py3.x: Urllib库 变化: 在Pytho2.x中使用import urllib2——-对应的,在Python3.x中会使用import urllib.request,urllib.error. 在Pytho2.x中使用import urllib——-对应的,在Python3.x中会使用import urllib.request,urllib.error,…
在Python 3中,urllib2被合并到了urllib中,叫做urllib.request 和 urllib.error .urllib整个模块分为urllib.request, urllib.parse, urllib.error. HTTP 请求方法: 根据 HTTP 标准,HTTP 请求可以使用多种请求方法. HTTP1.0 定义了三种请求方法: GET, POST 和 HEAD方法. HTTP1.1 新增了六种请求方法:OPTIONS.PUT.PATCH.DELETE.TRACE 和…
Item 22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples For example, say you want to record the grades of a set of students whose names aren't konwn in advance. You can define a class to store the names in a dictionary instead of…
Item 14: Prefer Exceptions to Returning None Functions that returns None to indicate special meaning are error prone because None and other values (e.g., zero, the empty string) all evaluate to False in conditional expressions. Raise exceptions to in…
一.错误和异常 1.异常处理 >>> while True: ... try: ... x = int(raw_input("Please enter a number: ")) ... break ... except ValueError: ... print "Oops! That was no valid number. Try again..." ... try 语句按如下方式工作: 首先,执行 try 子句 (在 try 和 excep…
一.模块 模块是包括 Python 定义和声明的文件.文件名就是模块名加上 .py 后缀.模块的模块名(做为一个字符串)可以由全局变量 __name__ 得到. 1. 模块可以导入其他的模块. 一个(好的)习惯是将所有的 import 语句放在模块的开始(或者是脚本),这并非强制. 被导入的模块名会放入当前模块的全局符号表中. from fibo import * :这样可以导入所有除了以下划线( _ )开头的命名. 需要注意的是在实践中往往不鼓励从一个模块或包中使用 * 导入所有,因为这样会让…