今日所学内容

1.函数部分:

#函数的三种定义方式
#1.无参函数:不需要外部传入的参数
#2.有参函数:需要接受外部传入的参数
#3.空函数:
def func():
pass#pass代表说明都不用做
# 遇到一些比较难实现的功能,会导致暂时无法继续编写代码。
# 所以一般在生产开发中,都会将所有功能实现定义成空函数
def func2():
print('k')
#把函数对象传入字典中
dict1={
'':func,
'':func2
}
choice=input("input:").strip()
#若用户选择函数对象对应的key值,则调用对象
if choice in dict1:
dict1[choice]()
# 函数的对象
# 指函数名指向的内存地址
# '''
# print(func)#调用的时候把func指向某个内存地址
函数嵌套:
嵌套定义:
在函数内,定义函数
嵌套调用
'''
#嵌套函数调用
#通过函数内部的返回值调用
#方法一
def func1():
print('func1')
def func2():
print('func2')
def func3():
print('func3')
return func3
return func2
func2=func1()
func2()

方法二

def func1():
print('func1')
def func2():
print('func2')
def func3():
print('func3')
func3()
func2()
func1()
名称空间
python解释器自带的:内置名称空间
自定义的py文件内,顶着最左边定义的,全局名称空间
函数内部定义的:局部名称空间
2.模块与包
# import 模块名---->
import day_03#文件夹可以叫做一个模块 from day_03 import 函数嵌套
#从day_03里面导入 函数嵌套 然后会自动执行 函数嵌套里面的代码
#python 为脚本语言 导入模块后就可以运行
函数嵌套.func1()
一些常用模块
1.
time模块,时间模块
import time
print(time.time())#获取当前时间戳
#等待
time.sleep(2)
print(time.time())
2.OS模块
import os
#os.path获取操作系统中的路径 print(os.path.exists('time模块.py'))
#判断此文件是否在当前目录中,用的是相对路径
# 若判断其他目录下的,用绝对路径 print(os.path.dirname(__file__))#获取当前文件的根目录 3.sys模块
# sys 获取python在环境变量中的路径
import  sys
print(sys.path)
反序列化
json.loads
with open('user.json','r',encoding='utf-8')as f:
res=f.read()
print(json.loads(res))
dump内部自动转化
with open('usr1.json','wt',encoding='utf-8')as f:
json.dump(user_info,f)#直接将user_info转化为str到句柄f(即文件中)
load直接从文件读字典型
with open('usr1.json','r',encoding='utf-8')as f:

    print(json.load(f))#即json.load自动触发f.read()

3.爬虫相关

'''
http协议:
请求url:(Request URL: )
https://www.baidu.com/
请求方式:
Request Method: GET
请求头Cookie:可能需要关注
User-Agent: 用来证明你是浏览器
注意:去浏览器的resquests hearder 中找
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36
Host:www.baidu.com(当前网站的返还)
'''
#requests模块的使用
import requests
response=requests.get(url='https://www.baidu.com/')#往百度的网站里发送请求
response.encoding='utf-8'
print(response)#<Response [200]>打印请求结果
print(response.status_code)#
# #返回响应文本
 print(response.text) with open('baidu.html','w',encoding='utf-8')as f:     f.write(response.text)
res=requests.get(url='https://video.pearvideo.com/mp4/adshort/20190613/cont-1565846-14013215_adpkg-ad_hd.mp4')
print(res.content)
with open('视频.mp4','wb')as f:
f.write(res.content)

python_day03的更多相关文章

随机推荐

  1. 备战双 11!蚂蚁金服万级规模 K8s 集群管理系统如何设计?

    作者 | 蚂蚁金服技术专家 沧漠 关注『阿里巴巴云原生』公众号,回复关键词"1024",可获取本文 PPT. 前言 Kubernetes 以其超前的设计理念和优秀的技术架构,在容器 ...

  2. ESP8266开发之旅 应用篇① 局域网应用 ——炫酷RGB彩灯

    1.前言     这一篇,博主将教大家怎么去实现一个WiFi RGB彩灯.     先来一个博主已经实现功能的图片,如下:     当然,博主也拍了运行视频,请点击 传输门. 1.1 知识储备     ...

  3. Apollo报错找不到apollo.meta的问题解决方案

    问题描述 Apollo报错,找不到apoll.meta,但是明明配置了apollo-env.properties到apollo-client内了. apollo-env.properties pro. ...

  4. 追查Could not get a databaseId from dataSource

    Mybatis 创建连接池的时候报错: ERROR 2017-03-15 00:44:50,333 commons.JakartaCommonsLoggingImpl:38 Could not get ...

  5. MySQL基础篇(1)SQL基础

    SQL是Structure Query Language(结构化查询语言)的缩写,它是使用关系模型的数据库应用语言. 一.SQL分类(DDL,DML,DCL) DDL(Data Definition ...

  6. 浅谈Retinex

    Retinex是上个世纪七十年代由Land提出的色彩理论.我认为其核心思想基于俩点 (1)在颜色感知时,人眼对局部相对光强敏感程度要优于绝对光强. (2)反射分量R(x,y)储存有无光源物体的真实模样 ...

  7. linux shell 小技能

    环境: [root@test ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@test ~]# uname -a Linux ...

  8. Web for pentester_writeup之File Include篇

    Web for pentester_writeup之File Include篇 File Include(文件包涵) Example 1 加一个单引号 从报错中我们可以获取如下信息: 当前文件执行的代 ...

  9. MySQL系统变量auto_increment_increment与auto_increment_offset学习总结

    在MySQL中,系统变量auto_increment_increment与auto_increment_offset是与自增列相关的两个参数变量.在官方文档中,将其划分为Replication Mas ...

  10. 《Effective Java》 读书笔记(三) 使用私有构造方法或枚举实现单例类

    1.单例类到现在为止算是比较熟悉的一种设计模式了,最开始写单例模式是在C#里面,想要自己实现一个单例类,代码如下: public class Instance { private static rea ...