码迷,mamicode.com
首页 > 编程语言 > 详细

python模块整理

时间:2017-05-25 00:03:27      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:class   index   res   request   highlight   进制   pen   logs   read   

一、time模块:import time

  1、time.sleep(3)   #单位为妙

 

 

二、urllib

  1、传递一个url地址得到其html内容:from urllib.request import urlopen

from  urllib.request  import urlopen
res = urlopen(‘http://crm.oldboyedu.com‘).read()   #打印出的是16进制
print(res.decode(‘utf-8‘))     #  转换为汉字

def index(url):
    def get():
        old_boy= urlopen(url).read()
        return old_boy
    return get

old_boy = index(‘http://crm.oldboyedu.com‘)  
print(old_boy.__closure__[0].cell_contents)   #每一个函数都有一个__closure__函数,如果是闭包函数,则其cell_contents方法返回闭包的值:http://crm.oldboyedu.com
print(old_boy().decode(‘utf-8‘))

 

 

python模块整理

标签:class   index   res   request   highlight   进制   pen   logs   read   

原文地址:http://www.cnblogs.com/wangkc/p/6901322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!