python【第五篇】常用模块学习
1.模块
a.定义:本质就是.py结尾的python文件,逻辑上组织python代码,实现某种功能。例:文件名test.py-->模块名test。
b.导入方法:imort moduname
from mdname import *
from mdname import name as rename
...
c.import本质(路径搜索和搜索路径)
d.导入优化:from mdname import test
e.模块分类:标准库内的模块、开源模块、自定义模块。
2.time &datetime模块
Python的时间模块主要有两个:time和datetime。
2.1 time模块
Python的time模块实现主要调用C库,所以各个平台可能有所不同。time模块表示时间的有三种类型:
(1)timestamp 时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。返回时间戳方式的函数主要有time(),clock()等;
(2)struct_time 时间元组,共有九个元素。返回struct_time的函数主要有gmtime(),localtime(),strptime();
- tm_year 2018
- tm_mon 1 到 12
- tm_mday 1 到 31
- tm_hour 0 到 23
- tm_min 0 到 59
- tm_sec 0 到 61 (60或61 是闰秒)
- tm_wday 0到6 (0是周一)
- tm_yday 1 到 366(儒略历)
- tm_isdst -1, 0, 1, -1是决定是否为夏令时的旗帜
(3)format time 格式化时间,自定义格式和固定格式。相当于把时间转换成可读性比较高的字符串。
补充:UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间。中国北京时间(东八区)为UTC+8。DST(Daylight Saving Time)为夏令时。
- #_*_coding:utf-8_*_
- import time
- # print(time.clock()) #返回处理器时间,3.3开始已废弃 , 改成了time.process_time()测量处理器运算时间,不包括sleep时间,不稳定,mac上测不出来
- # print(time.altzone) #返回与utc时间的时间差,以秒计算\
- # print(time.asctime()) #返回时间格式"Fri Aug 19 11:14:16 2016",
- # print(time.localtime()) #返回本地时间 的struct time对象格式
- # print(time.gmtime(time.time()-800000)) #返回utc时间的struc时间对象格式
- # print(time.asctime(time.localtime())) #返回时间格式"Fri Aug 19 11:14:16 2016",
- #print(time.ctime()) #返回Fri Aug 19 12:38:29 2016 格式, 同上
- # 日期字符串 转成 时间戳
- # string_2_struct = time.strptime("2016/05/22","%Y/%m/%d") #将 日期字符串 转成 struct时间对象格式
- # print(string_2_struct)
- # #
- # struct_2_stamp = time.mktime(string_2_struct) #将struct时间对象转成时间戳
- # print(struct_2_stamp)
- #将时间戳转为字符串格式
- # print(time.gmtime(time.time()-86640)) #将utc时间戳转换成struct_time格式
- # print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) #将utc struct_time格式转成指定的字符串格式
- #时间加减
- import datetime
- # print(datetime.datetime.now()) #返回 2016-08-19 12:47:03.941925
- #print(datetime.date.fromtimestamp(time.time()) ) # 时间戳直接转成日期格式 2016-08-19
- # print(datetime.datetime.now() )
- # print(datetime.datetime.now() + datetime.timedelta(3)) #当前时间+3天
- # print(datetime.datetime.now() + datetime.timedelta(-3)) #当前时间-3天
- # print(datetime.datetime.now() + datetime.timedelta(hours=3)) #当前时间+3小时
- # print(datetime.datetime.now() + datetime.timedelta(minutes=30)) #当前时间+30分
- #
- # c_time = datetime.datetime.now()
- # print(c_time.replace(minute=3,hour=2)) #时间替换
对应格式:
- %a 本地(locale)简化星期名称
- %A 本地完整星期名称
- %b 本地简化月份名称
- %B 本地完整月份名称
- %c 本地相应的日期和时间表示
- %d 一个月中的第几天(01 - 31)
- %H 一天中的第几个小时(24小时制,00 - 23)
- %I 第几个小时(12小时制,01 - 12)
- %j 一年中的第几天(001 - 366)
- %m 月份(01 - 12)
- %M 分钟数(00 - 59)
- %p 本地am或者pm的相应符
- %S 秒(01 - 61)
- %U 一年中的星期数。(00 - 53星期天是一个星期的开始。)第一个星期天之前的所有天数都放在第0周。
- %w 一个星期中的第几天(0 - 6,0是星期天)
- %W 和%U基本相同,不同的是%W以星期一为一个星期的开始。
- %x 本地相应日期
- %X 本地相应时间
- %y 去掉世纪的年份(00 - 99)
- %Y 完整的年份
- %Z 时区的名字(如果不存在为空字符)
- %% ‘%’字符
格式对应
3.random模块
- #!/usr/bin/env python
- #_*_encoding: utf-8_*_
- import random
- print (random.random()) #0.6445010863311293
- #random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0
- print (random.randint(1,7)) #
- #random.randint()的函数原型为:random.randint(a, b),用于生成一个指定范围内的整数。
- # 其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= b
- print (random.randrange(1,10)) #
- #random.randrange的函数原型为:random.randrange([start], stop[, step]),
- # 从指定范围内,按指定基数递增的集合中 获取一个随机数。如:random.randrange(10, 100, 2),
- # 结果相当于从[10, 12, 14, 16, ... 96, 98]序列中获取一个随机数。
- # random.randrange(10, 100, 2)在结果上与 random.choice(range(10, 100, 2) 等效。
- print(random.choice('liukuni')) #i
- #random.choice从序列中获取一个随机元素。
- # 其函数原型为:random.choice(sequence)。参数sequence表示一个有序类型。
- # 这里要说明一下:sequence在python不是一种特定的类型,而是泛指一系列的类型。
- # list, tuple, 字符串都属于sequence。有关sequence可以查看python手册数据模型这一章。
- # 下面是使用choice的一些例子:
- print(random.choice("学习Python"))#学
- print(random.choice(["JGood","is","a","handsome","boy"])) #List
- print(random.choice(("Tuple","List","Dict"))) #List
- print(random.sample([1,2,3,4,5],3)) #[1, 2, 5]
- #random.sample的函数原型为:random.sample(sequence, k),从指定序列中随机获取指定长度的片断。sample函数不会修改原有序列。
实际应用:
- #!/usr/bin/env python
- # encoding: utf-8
- import random
- import string
- #随机整数:
- print( random.randint(0,99)) #
- #随机选取0到100间的偶数:
- print(random.randrange(0, 101, 2)) #
- #随机浮点数:
- print( random.random()) #0.2746445568079129
- print(random.uniform(1, 10)) #9.887001463194844
- #随机字符:
- print(random.choice('abcdefg&#%^*f')) #f
- #多个字符中选取特定数量的字符:
- print(random.sample('abcdefghij',3)) #['f', 'h', 'd']
- #随机选取字符串:
- print( random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )) #apple
- #洗牌#
- items = [1,2,3,4,5,6,7]
- print(items) #[1, 2, 3, 4, 5, 6, 7]
- random.shuffle(items)
- print(items) #[1, 4, 7, 2, 5, 3, 6]
随机生成验证码:
- # _*_ coding:utf-8 _*_
- __author__ = "ZingP"
- import random
- security_code = ''
- for i in range(0,5):
- j = random.randrange(0,5)
- if i == j:
- ptm = random.randint(0,9)
- else:
- ptm = chr(random.randint(97,122))
- security_code += str(ptm)
- print('security code:',security_code )
4.os
提供对操作系统进行调用的接口:
- os.path.basename() 去掉目录路径, 返回文件名
- os.path.dirname() 去掉文件名, 返回目录路径
- os.path.join() 将分离的各部分组合成一个路径名
- os.path.split() 返回目录和文件的元组 (dir, file)【给的是目录则会返回最后一个目录名和前面的路径】
- os.path.splitdrive() 返回盘符和路径的元组 (drivename, pathname)
- os.path.splitext() 返回文件名和扩展名的元组(filename, extension)
- os.path.abspath() 获得绝对路径(不太好使)
- os.path.normpath() 规范path字符串形式
- os.path.getatime() 返回最近访问时间的时间戳
- os.path.getctime() 返回文件创建时间的时间戳
- os.path.getmtime() 返回最近文件修改时间的时间戳
- os.path.getsize() 返回文件或目录大小(以字节为单位)
- os.path.walk() 搜索目录下的所有文件
- os.path.exists() 指定路径(文件或目录)是否存在
- os.path.isabs() 指定路径是否为绝对路径
- os.path.isdir() 指定路径是否存在且为一个目录
- os.path.isfile() 指定路径是否存在且为一个文件
- os.path.islink() 指定路径是否存在且为一个符号链接
- os.path.ismount() 指定路径是否存在且为一个挂载点
- os.path.samefile() 两个路径名是否指向同个文件
- os.environ 获取系统环境变量
- os.linesep 获取本系统的换行符
- os.sep 获取路径分割符
- os.pathsep 路径与路径之间的分割符字符串
- os.curdir 当前工作目录的字符串名称(.)
- os.pardir (当前工作目录的)父目录字符串名称(..)
- os.name 输出字符串指示当前系统平台'nt'->win;'posix'->Linux
- os.rename(old, new) 重命名
- os.remove() 删除文件
- os.listdir() 列出目录下的文件(目录也是文件):
- os.getcwd() 获取当前工作目录:
- os.chdir() 改变工作目录:
- os.makedirs() 创建多级目录
- os.mkdir() 创建单个目录
- os.removedirs() 删除所给路径最后一个目录下所有空目录。
- os.rmdir("test") 删除单个目录
- os.stat(file) 获取文件属性
- os.chmod(file) 修改文件权限与时间戳
- os.system("dir") 执行操作系统命令
- os.exec()/os.execvp()启动新进程
- os.spawnv() 在后台执行程序
- os.exit()/os._exit() 终止当前进程
- os.ismount() 是否挂载
5.sys
常用函数
- sys.argv # 命令行参数List,python t.py 1 sys.arsv[0]是t.py
- sys.exit(n) # 退出程序,正常退出时exit(0)
- sys.version # 获取Python解释程序的版本信息
- sys.maxint # 最大的Int值
- sys.path # 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
- sys.platform # 返回操作系统平台名称
- sys.getrecursionlimit() # 获取最大递归层数
- sys.setrecursionlimit(2000) # 设置最大递归层数为2000
- sys.stdout.write('please:')
- val = sys.stdin.readline()[:-1]
- sys.modules # 已加载模块的字典
- sys.version # 版本信息
- sys.version_info # 版本信息的命名元组
- sys.copyright # 获取python版权相关信息
- sys.builtin_module_names # 获得python内建模块名称(字符串元组)
示例:
- >>> import sys
- >>> sys.getrecursionlimit()
- 1000
- >>> sys.setrecursionlimit(2000)
- >>> sys.getrecursionlimit()
- 2000
6.shutil模块
更多:http://www.cnblogs.com/wupeiqi/articles/4963027.html
7.json & pickle模块
用于序列化的两个模块
json,用于字符串 和 python数据类型间进行转换
pickle,用于python特有的类型 和 python的数据类型间进行转换
Json模块提供了四个功能:dumps、dump、loads、load
pickle模块提供了四个功能:dumps、dump、loads、load
- import pickle
- a = {'a':'bc','c':'hello','d':123,'e':'world'}
- f = open('a.pkl','wb')
- pickle.dump(a,f)#如果跨语言平台使用json
- f.close()
- '''
- >>> a = {'a':'bc','c':'hello','d':123,'e':'world'}
- >>> import json
- >>> json.dumps(a)
- '{"a": "bc", "d": 123, "e": "world", "c": "hello"}'
- >>> b = json.dumps(a)
- >>> json.loads(b)
- {'a': 'bc', 'd': 123, 'e': 'world', 'c': 'hello'}
- '''
- import pickle
- f = open('a.pkl','rb')
- acc = pickle.load(f)
- print(acc)
8.shelve
9.xml处理
10.yaml处理
11.configparser
12.hashlib
用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法
- #! /usr/bin/env python3
- import hashlib
- # ######## md5 ########
- hash = hashlib.md5()
- hash.update(b'love you baby..')
- print(hash.hexdigest())
- # ######## sha1 ########
- hash = hashlib.sha1()
- hash.update(b'love you baby..')
- print(hash.hexdigest())
- # ######## sha256 ########
- hash = hashlib.sha256()
- hash.update(b'love you baby..')
- print(hash.hexdigest())
- # ######## sha384 ########
- hash = hashlib.sha384()
- hash.update(b'love you baby..')
- print(hash.hexdigest())
- # ######## sha512 ########
- hash = hashlib.sha512()
- hash.update(b'love you baby..')
- print(hash.hexdigest())
以上加密算法虽然依然非常厉害,但时候存在缺陷,即:通过撞库可以反解。所以,有必要对加密算法中添加自定义key再来做加密。
- #! /usr/bin/env python3
- import hashlib
- # ######## md5 ########
- hash = hashlib.md5(b'898oaFs09f')
- hash.update(b'love you baby...')
- print(hash.hexdigest())
还不够吊?python 还有一个 hmac 模块,它内部对我们创建 key 和 内容 再进行处理然后再加密
- import hmac
- h = hmac.new(b'zingp')
- h.update(b'hello')
- print(h.hexdigest())
13.subprocess
可以执行shell命令的相关模块和函数有:
- os.system
- os.spawn*
- os.popen* --废弃
- popen2.* --废弃
- commands.* --废弃,3.x中被移除
以上执行shell命令的相关的模块和函数的功能均在 subprocess 模块中实现,并提供了更丰富的功能。
call
执行命令,返回状态码
- ret = subprocess.call(["ls", "-l"], shell=False)
- ret = subprocess.call("ls -l", shell=True)
shell = True ,允许 shell 命令是字符串形式
check_call
执行命令,如果执行状态码是 0 ,则返回0,否则抛异常
- subprocess.check_call(["ls", "-l"])
- subprocess.check_call("exit 1", shell=True)
check_output
执行命令,如果状态码是 0 ,则返回执行结果,否则抛异常
- subprocess.check_output(["echo", "Hello World!"])
- subprocess.check_output("exit 1", shell=True)
调用subprocess.run(...)是推荐的常用方法,在大多数情况下能满足需求。
- >>> subprocess.run(["ls", "-l"]) # doesn't capture output
- CompletedProcess(args=['ls', '-l'], returncode=0)
- >>> subprocess.run("exit 1", shell=True, check=True)
- Traceback (most recent call last):
- ...
- subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
- >>> subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE)
- CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,
- stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n')
subprocess.Popen(...)
用于执行复杂的系统命令
参数:
- args:shell命令,可以是字符串或者序列类型(如:list,元组)
- bufsize:指定缓冲。0 无缓冲,1 行缓冲,其他 缓冲区大小,负值 系统缓冲
- stdin, stdout, stderr:分别表示程序的标准输入、输出、错误句柄
- preexec_fn:只在Unix平台下有效,用于指定一个可执行对象(callable object),它将在子进程运行之前被调用
- close_sfs:在windows平台下,如果close_fds被设置为True,则新创建的子进程将不会继承父进程的输入、输出、错误管道。
所以不能将close_fds设置为True同时重定向子进程的标准输入、输出与错误(stdin, stdout, stderr)。 - shell:同上
- cwd:用于设置子进程的当前目录
- env:用于指定子进程的环境变量。如果env = None,子进程的环境变量将从父进程中继承。
- universal_newlines:不同系统的换行符不同,True -> 同意使用 \n
- startupinfo与createionflags只在windows下有效
将被传递给底层的CreateProcess()函数,用于设置子进程的一些属性,如:主窗口的外观,进程的优先级等等
- import subprocess
- ret1 = subprocess.Popen(["mkdir","t1"])
- ret2 = subprocess.Popen("mkdir t2", shell=True)
终端输入的命令分为两种:
- 输入即可得到输出,如:ifconfig
- 输入进行某环境,依赖再输入,如:python
- import subprocess
- obj = subprocess.Popen("mkdir t3", shell=True, cwd='/home/dev',)
示例:
- import subprocess
- obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- obj.stdin.write('print 1 \n ')
- obj.stdin.write('print 2 \n ')
- obj.stdin.write('print 3 \n ')
- obj.stdin.write('print 4 \n ')
- obj.stdin.close()
- cmd_out = obj.stdout.read()
- obj.stdout.close()
- cmd_error = obj.stderr.read()
- obj.stderr.close()
- print cmd_out
- print cmd_error
- import subprocess
- obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- obj.stdin.write('print 1 \n ')
- obj.stdin.write('print 2 \n ')
- obj.stdin.write('print 3 \n ')
- obj.stdin.write('print 4 \n ')
- out_error_list = obj.communicate()
- print out_error_list
- import subprocess
- obj = subprocess.Popen(["python"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out_error_list = obj.communicate('print "hello"')
- print out_error_list
14.logging模块
用于便捷记录日志且线程安全的模块
- #! /usr/bin/env python3
- import logging
- logging.basicConfig(filename='mylog.log',
- format='%(asctime)s - %(name)s - %(levelname)s -%(module)s: %(message)s',
- datefmt='%Y-%m-%d %H:%M:%S %p',
- level=10)
- # level设置值就是当出现这个情况或比这个值更严重的情况才记录日志
- logging.debug('')
- logging.info('')
- logging.warning('')
- logging.error('')
- logging.critical('')
- logging.log(10, 'logqqq')
运行结果,mylog.log文件中的内容:
- 2016-11-22 10:52:37 AM - root - DEBUG -test1: 1111
- 2016-11-22 10:52:37 AM - root - INFO -test1: 2222
- 2016-11-22 10:52:37 AM - root - WARNING -test1: 3333
- 2016-11-22 10:52:37 AM - root - ERROR -test1: 4444
- 2016-11-22 10:52:37 AM - root - CRITICAL -test1: 5555
- 2016-11-22 10:52:37 AM - root - DEBUG -test1: logqqq
日志的几个等级:
- CRITICAL = 50
- FATAL = CRITICAL
- ERROR = 40
- WARNING = 30
- WARN = WARNING
- INFO = 20
- DEBUG = 10
- NOTSET = 0
日志的格式,可以配置下面的属性:
15.re正则表达式
常用正则符号
- '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行
- '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)
- '$' 匹配字符结尾,或e.search("foo$","bfoo\nsdfsf",flags=re.MULTILINE).group()也可以
- '*' 匹配*号前的字符0次或多次,re.findall("ab*","cabb3abcbbac") 结果为['abb', 'ab', 'a']
- '+' 匹配前一个字符1次或多次,re.findall("ab+","ab+cd+abb+bba") 结果['ab', 'abb']
- '?' 匹配前一个字符1次或0次
- '{m}' 匹配前一个字符m次
- '{n,m}' 匹配前一个字符n到m次,re.findall("ab{1,3}","abb abc abbcbbb") 结果'abb', 'ab', 'abb']
- '|' 匹配|左或|右的字符,re.search("abc|ABC","ABCBabcCD").group() 结果'ABC'
- '(...)' 分组匹配,re.search("(abc){2}a(123|456)c", "abcabca456c").group() 结果 abcabca456c
- '\A' 只从字符开头匹配,re.search("\Aabc","alexabc") 是匹配不到的
- '\Z' 匹配字符结尾,同$
- '\d' 匹配数字0-9
- '\D' 匹配非数字
- '\w' 匹配[A-Za-z0-9]
- '\W' 匹配非[A-Za-z0-9]
- 's' 匹配空白字符、\t、\n、\r , re.search("\s+","ab\tc1\n3").group() 结果 '\t'
- '(?P<name>...)' 分组匹配 re.search("(?P<province>[0-9]{4})(?P<city>[0-9]{2})(?P<birthday>[0-9]{4})","").groupdict("city") 结果{'province': '', 'city': '', 'birthday': ''}
示例:
- # _*_ coding:utf-8 _*_
- __author__ = "ZingP"
- import re
- a = 'abc1234\(hh+12hhdd][wdbrgwnq'
- # '.'默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行
- b = re.search('.', a)
- print(b.group()) # result:a
- c = re.search('.', '\nbcd', flags=re.DOTALL)
- print(c) # result:<_sre.SRE_Match object; span=(0, 1), match='\n'>
- # 这里print(c.group()) 什么也打印不了,\n不能用group???
- # '^'匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)
- print(re.search('^b', 'bard').group()) # result: b
- # '$'匹配字符结尾,或e.search("foo$","bfoo\nsdfsf",flags=re.MULTILINE).group()也可以
- print(re.search('2$', 'ggcba12').group()) # result:2
- # 匹配*号前的字符0次或多次
- print(re.search('ac*', 'accqwiuewac457ab').group()) # result:acc
- print(re.findall('ac*', 'accqwiuewac457ab')) # result:['acc', 'ac', 'a']
- # '+' 匹配前一个字符1次或多次
- print(re.findall("ab+", "ab+cd+abb+bba")) # result:['ab', 'abb']
- # '?' 匹配前一个字符1次或0次
- print(re.findall('ab?', 'cdab90oladh')) # result:['ab', 'a']
- # '{m}' 匹配前一个字符m次
- print(re.findall('ab{3}', 'cdab90olabbbbcdh')) # result:['abbb']
- # '{n,m}' 匹配前一个字符n到m次,re.findall("ab{1,3}","abb abc abbcbbb") 结果'abb', 'ab', 'abb']
- print(re.findall('ab{1,3}', 'cdab90olabbbbcdh')) # ['ab', 'abbb']
- # '|' 匹配|左或|右的字符,re.search("abc|ABC","ABCBabcCD").group() 结果'ABC'
- print(re.findall("abc|ABC","ABCB23abcCD")) # ['ABC', 'abc']
- # '(...)' 分组匹配, 结果 abcabca456c
- print(re.search("(abc){2}a(123|456)c", "abcabca456c").group()) # abcabca456c
- # 关于反斜杠
- print(re.search(r'\\', '\d\c\b')) # <_sre.SRE_Match object; span=(0, 1), match='\\'>
- print(re.findall(r'\\', 'ss\d\c\b')) # ['\\', '\\']???
- print(re.search('\\\\', 'd\c\b').group()) # \
- print(re.search("(?P<id>[0-9]+)(?P<name>[A-Za-z]+)", "as123alex+++").groupdict())
- # {'name': 'alex', 'id': '123'}
- # re.sub匹配到的替换 count为替换次数
- print(re.sub('[0-9]+', '|', 'abc12df34hh56n', count=2)) # abc|df|hh56n
- print(re.sub('[0-9]+', '|', 'abc12df34hh56n', count=3)) # abc|df|hh|n
- print(re.findall("[0-9]{1,3}","aa1xxx2y3456")) # ['1', '2', '345', '6']
- print(re.findall("[0-9]{1,3}","aa1xxx2y3456")) # ['1', '2', '345', '6']
语法:
- re.match 从头开始匹配
- re.search 匹配包含
- re.findall 把所有匹配到的字符放到以列表中的元素返回
- re.splitall 以匹配到的字符当做列表分隔符
- re.sub 匹配字符并替换
了解几个匹配模式:
- re.I(re.IGNORECASE): 忽略大小写(括号内是完整写法,下同)
- M(MULTILINE): 多行模式,改变'^'和'$'的行为(参见上图)
- S(DOTALL): 点任意匹配模式,改变'.'的行为
16.glob模块
python【第五篇】常用模块学习的更多相关文章
- Python 之路 Day5 - 常用模块学习
本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...
- Python之路,Day5 - 常用模块学习 (转载Alex)
本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...
- Day5 - Python基础5 常用模块学习
Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...
- 第六章:Python基础の反射与常用模块解密
本课主题 反射 Mapping 介绍和操作实战 模块介绍和操作实战 random 模块 time 和 datetime 模块 logging 模块 sys 模块 os 模块 hashlib 模块 re ...
- Python第五章__模块介绍,常用内置模块
Python第五章__模块介绍,常用内置模块 欢迎加入Linux_Python学习群 群号:478616847 目录: 模块与导入介绍 包的介绍 time &datetime模块 rando ...
- 简学Python第五章__模块介绍,常用内置模块
Python第五章__模块介绍,常用内置模块 欢迎加入Linux_Python学习群 群号:478616847 目录: 模块与导入介绍 包的介绍 time &datetime模块 rando ...
- Python之路,Day21 - 常用算法学习
Python之路,Day21 - 常用算法学习 本节内容 算法定义 时间复杂度 空间复杂度 常用算法实例 1.算法定义 算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的 ...
- Python【第五篇】模块、包、常用模块
一.模块(Module) 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...
- Python常用模块学习
1.模块介绍 2.time & datetime模块 3.random 4.os 5.sys 6.shutil 7.json&pickle 8.shelve 9.xml处理 10.ya ...
- Python基础5 常用模块学习
本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...
随机推荐
- QT: QByteArray储存二进制数据(包括结构体,自定义QT对象)
因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类 1. 利用memcpy拷贝内存数据 / ...
- C#_delegate - 用委托实现事件,Display和Log类都使用Clock对象
//public event SecondChangeHandler OnSecondChange; 若将委托加上event,则视作是事件,不是委托,外围就不能直接对OnSecondChange传值 ...
- SQL Server 中添加用户
在对象资源管理器中点击安全性,选择登录名-新建登录名
- LoadRunner测试问题
1.关于Error -27791: Error -27790:Error -27740: 错误如下: Action.c(198): Error -27791: Server has shut down ...
- IIS7下w3wp.exe进程CPU100%问题解决办法
IIS下经常会出现w3wp.exe进程的CPU使用率达到100%的情况,在IIS7出现之前,要想确定问题所在,可以通过WinDbg来调试分析,但整个过程对技术水平要求非常高,可以参考http:// ...
- 《Mysql 公司职员学习篇》 第二章 小A的惊喜
第二章 小A的惊喜 ---- 认识数据库 吃完饭后,小Y和小A回到了家里,并打开电脑开始学习Mysql. 小Y:"小A,你平时的Excell文件很多的情况下,怎么样存放Exce ...
- Azure PowerShell (二)云服务
. 浏览云服务Get-AzureService | Select-Object -Property ServiceName, Location,`@{Name='ProdIP';Expression ...
- 异常的应用finally与总结
一.finally{ },finally块中放入一定要执行的代码,通常用来关闭数据库,关闭链接,节约资源,所以finally中的内容一定要被执行,但是有一张情况不被执行,就是catch(Excep ...
- 介绍map.entry接口
Map是java中的接口,Map.Entry是Map的一个内部接口.java.util.Map.Entry接口主要就是在遍历map的时候用到. Map提供了一些常用方法,如keySet().entry ...
- Activti跳过中间节点的helloworld实例程序
http://blog.csdn.net/songzheng_741/article/details/17289633 此实例是一个最简单的在运行时人为动态改变流程运转的实例,意在为任意流.驳回等功能 ...