Python学习——python的常用模块

原文作者:佛山小程序员
原文链接:https://blog.csdn.net/weixin_44192923/article/details/86563253


模块:用一堆代码实现了某个功能的代码集合,模块是不带 .py 扩展的另外一个 Python 文件的文件名。

最近开始整理python的资料,会陆续放到博客中存档。找了几个qq群,其中有一个群78486745。后面就没怎么加群了,还是需要看官方文档为主

一、time & datetime模块

 1 import time2 import datetime3 4 print(time.asctime())      # 返回时间格式:Sun May  7 21:46:15 20175 print(time.time())         # 返回时间戳 ‘1494164954.6677325’6 print(time.gmtime())       # 返回本地时间 的struct time对象格式,time.struct_time(tm_year=2017, tm_mon=5, tm_mday=7, tm_hour=22, tm_min=4, tm_sec=53, tm_wday=6, tm_yday=127, tm_isdst=0)7 print(time.localtime())    # 返回本地时间 的struct time对象格式,time.struct_time(tm_year=2017, tm_mon=5, tm_mday=7, tm_hour=22, tm_min=4, tm_sec=53, tm_wday=6, tm_yday=127, tm_isdst=0)8 print(time.gmtime(time.time()-800000))   # 返回utc时间的struc时间对象格式9 print(time.asctime(time.localtime()))    # 返回时间格式Sun May  7 22:15:09 2017
10 print(time.ctime())                      # 返回时间格式Sun May  7 22:15:09 2017
11 print(time.strftime('%Y-%m-%d'))         #默认当前时间 2017-05-07
12 print(time.strftime('%Y-%m-%d',time.localtime())) #默认当前时间 2017-05-07
13
14 string_struct = time.strptime("2016/05/22","%Y/%m/%d") # 将日期字符串 转成 struct时间对象格式
15 print(string_struct)                     # 返回struct time对象格式 time.struct_time(tm_year=2016, tm_mon=5, tm_mday=22, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=143, tm_isdst=-1)
16
17 # 将日期字符串转成时间戳
18 struct_stamp = time.mktime(string_struct) # 将struct time时间对象转成时间戳
19 print(struct_stamp)                         # 返回时间戳 ‘1463846400.0’
20
21 # 将时间戳转为字符串格式
22 print(time.gmtime(time.time()-86640))         # 将utc时间戳转换成struct_time格式
23 print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) # 将utc struct_time格式转成指定的字符串格式
24
25
26 # 时间加减
27 print(datetime.datetime.now())           # 返回当前时间 2017-05-07 22:36:45.179732
28 print(datetime.date.fromtimestamp(time.time()))  # 时间戳直接转换成日期格式 2017-05-07
29 print(datetime.datetime.now() + datetime.timedelta(3))    # 返回时间在当前日期上 +3 天
30 print(datetime.datetime.now() + datetime.timedelta(-3))    # 返回时间在当前日期上 -3 天
31 print(datetime.datetime.now() + datetime.timedelta(hours= 3)) # 返回时间在当前时间上 +3 小时
32 print(datetime.datetime.now() + datetime.timedelta(minutes= 30)) # 返回时间在当前时间上 +30 分钟
33
34 c_time  = datetime.datetime.now()
35 print(c_time)                          # 当前时间为 2017-05-07 22:52:44.016732
36 print(c_time.replace(minute=3,hour=2)) # 时间替换 替换时间为‘2017-05-07 02:03:18.181732’
37
38 print(datetime.timedelta)      # 表示时间间隔,即两个时间点之间的长度
39 print (datetime.datetime.now() - datetime.timedelta(days=5))  # 返回时间在当前时间上 -5 天
40
41 # python 日历模块
42 import calendar
43
44 print(calendar.calendar(theyear= 2017))     # 返回2017年整年日历
45 print(calendar.month(2017,5))               # 返回某年某月的日历,返回类型为字符串类型
46
47 calendar.setfirstweekday(calendar.WEDNESDAY) # 设置日历的第一天(第一天以星期三开始)
48 cal = calendar.month(2017, 4)
49 print (cal)
50
51 print(calendar.monthrange(2017,5))        # 返回某个月的第一天和这个月的所有天数
52 print(calendar.monthcalendar(2017,5))     # 返回某个月以每一周为元素的序列
53
54 cal = calendar.HTMLCalendar(calendar.MONDAY)
55 print(cal.formatmonth(2017, 5))           # 在html中打印某年某月的日历
56
57 print(calendar.isleap(2017))             # 判断是否为闰年
58 print(calendar.leapdays(2000,2017))       # 判断两个年份间闰年的个数

二、random模块

1 import random2 3 # 随机数4 print(random.random())              # 返回一个随机小数'0.4800545746046827'5 print(random.randint(1,5))          # 返回(1-5)随机整型数据6 print(random.randrange(1,10))       # 返回(1-10)随机数据7 8 # 生成随机验证码9 code = ''
10 for i in range(4):
11     current = random.randrange(0,4)
12     if current != i:
13         temp = chr(random.randint(65,90))
14     else:
15         temp = random.randint(0,9)
16     code += str(temp)
17
18 print(code)

三、OS模块

1 import os2 3 print(os.getcwd())        # 获得当前工作目录4 print(os.chdir("dirname")) # 改变当前脚本的工作路径,相当于shell下的cd5 print(os.curdir)            # 返回当前目录‘.'6 print(os.pardir)            # 获取当前目录的父目录字符串名‘..'7 print(os.makedirs('dirname1/dirname2'))     # 可生成多层递归目录8 print(os.removedirs('dirname1/dirname2'))      # 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推9 print(os.mkdir('test4'))         # 生成单级目录;相当于shell中mkdir dirname
10 print(os.rmdir('test4'))        # 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname
11 print(os.listdir('/pythonStudy/s12/test'))   # 列出指定目录下的所有文件和子目录,包括隐藏文件,并以列表方式打印
12 print(os.remove('log.log'))            # 删除一个指定的文件
13 print(os.rename("oldname","newname"))    # 重命名文件/目录)
14 print(os.stat('/pythonStudy/s12/test'))     # 获取文件/目录信息
15 print(os.pathsep)            # 输出用于分割文件路径的字符串';'
16 print(os.name)               # 输出字符串指示当前使用平台。win->'nt'; Linux->'posix'
17 print(os.system(command='bash'))   # 运行shell命令,直接显示
18 print(os.environ)                  # 获得系统的环境变量
19 print(os.path.abspath('/pythonStudy/s12/test'))   # 返回path规范化的绝对路径
20 print(os.path.split('/pythonStudy/s12/test'))     # 将path分割成目录和文件名二元组返回
21 print(os.path.dirname('/pythonStudy/s12/test'))    # 返回path的目录。其实就是os.path.split(path)的第一个元素
22 print(os.path.basename('/pythonStudy/s12/test'))   # 返回path最后的文件名。如果path以/或\结尾,那么就会返回空值。即os.path.split(path)的第二个元素
23 print(os.path.exists('test'))                 # 判断path是否存在
24 print(os.path.isabs('/pythonStudy/s12/test'))    # 如果path是绝对路径,返回True
25 print(os.path.isfile('test'))                   # 如果path是一个存在的文件,返回True。否则返回False
26 print(os.path.isdir('/pythonStudy/s12/test'))    # 如果path是一个存在的目录,则返回True。否则返回False
27 print(os.path.getatime('/pythonStudy/s12/test'))   # 返回path所指向的文件或者目录的最后存取时间
28 print(os.path.getmtime('/pythonStudy/s12/test'))   # 返回path所指向的文件或者目录的最后修改时间

四、sys模块

import sysprint(sys.argv)          # 命令行参数List,第一个元素是程序本身路径
print(sys.exit(n))     # 退出程序,正常退出时exit(0)
print(sys.version)       # 获取python的版本信息
print(sys.path)          # 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
print(sys.platform)      # 返回操作平台的名称

五、shutil模块

import shutil
shutil.copyfileobj(fsrc, fdst, length=16*1024)      # 将文件内容拷贝到另一个文件中,可以是部分内容
shutil.copyfile(src, dst)                           # 拷贝文件
shutil.copymode(src, dst)                           # 仅拷贝权限。内容、组、用户均不变
shutil.copystat(src, dst)                           # 拷贝状态的信息,包括:mode bits, atime, mtime, flags
shutil.copy(src, dst)                               # 拷贝文件和权限
shutil.copy2(src, dst)                              # 拷贝文件和状态信息
shutil.move(src, dst)                               # 递归的去移动文件# base_name: 压缩包的文件名,也可以是压缩包的路径。只是文件名时,则保存至当前目录,否则保存至指定路径
# format: 压缩包种类,“zip”, “tar”, “bztar”,“gztar”
# root_dir: 要压缩的文件夹路径(默认当前目录)
# owner: 用户,默认当前用户
# group: 组,默认当前组
# logger: 用于记录日志,通常是logging.Logger对象
shutil.make_archive(base_name, format,root_dir,owner,group,logger)   # 创建压缩包并返回文件路径,例如:zip、tarshutil 对压缩包的处理是调用 ZipFile 和 TarFile 两个模块来进行的:# zipfile 压缩解压import zipfile
# 压缩
z = zipfile.ZipFile('laxi.zip', 'w')
z.write('a.log')
z.write('data.data')
z.close()# 解压
z = zipfile.ZipFile('laxi.zip', 'r')
z.extractall()
z.close()# tarfile 压缩解压import tarfile# 压缩
tar = tarfile.open('your.tar','w')
tar.add('/Users/wupeiqi/PycharmProjects/bbs2.zip', arcname='bbs2.zip')
tar.add('/Users/wupeiqi/PycharmProjects/cmdb.zip', arcname='cmdb.zip')
tar.close()# 解压
tar = tarfile.open('your.tar','r')
tar.extractall()  # 可设置解压地址
tar.close()

六、XML处理模块

# xml的格式如下,就是通过<>节点来区别数据结构的:
xmltest.xml<?xml version="1.0"?><data><country name="Liechtenstein"><rank updated="yes">2</rank><year>2008</year><gdppc>141100</gdppc><neighbor name="Austria" direction="E"/><neighbor name="Switzerland" direction="W"/></country><country name="Singapore"><rank updated="yes">5</rank><year>2011</year><gdppc>59900</gdppc><neighbor name="Malaysia" direction="N"/></country><country name="Panama"><rank updated="yes">69</rank><year>2011</year><gdppc>13600</gdppc><neighbor name="Costa Rica" direction="W"/><neighbor name="Colombia" direction="E"/></country></data> #  xml协议在各个语言里的都 是支持的,在python中可以用以下模块操作xml  import xml.etree.ElementTree as ETtree = ET.parse("xmltest.xml")
root = tree.getroot()
print(root.tag)#遍历xml文档
for child in root:print(child.tag, child.attrib)for i in child:print(i.tag,i.text)#只遍历year 节点
for node in root.iter('year'):print(node.tag,node.text)# 修改和删除xml文档内容import xml.etree.ElementTree as ETtree = ET.parse("xmltest.xml")
root = tree.getroot()#修改for node in root.iter('year'):new_year = int(node.text) + 1node.text = str(new_year)node.set("updated","yes")
tree.write("xmltest.xml")#删除nodefor country in root.findall('country'):rank = int(country.find('rank').text)if rank > 50:root.remove(country)
tree.write('output.xml')# 自己创建xml文档
import xml.etree.ElementTree as ETnew_xml = ET.Element("namelist")
name = ET.SubElement(new_xml, "name", attrib={"enrolled": "yes"})
age = ET.SubElement(name, "age", attrib={"checked": "no"})
age = ET.SubElement(name, "age")
age.text = '33'
name2 = ET.SubElement(new_xml, "name", attrib={"enrolled": "no"})
age = ET.SubElement(name2, "age")
age.text = '19'
et = ET.ElementTree(new_xml)  # 生成文档对象
et.write("test.xml", encoding="utf-8", xml_declaration=True)
ET.dump(new_xml)  # 打印生成的格式

七、configparser模块

用于生成和修改常见配置文档

# 好多软件的常见文档格式如下[DEFAULT]compressionlevel = 9serveraliveinterval = 45compression = yesforwardx11 = yes[bitbucket.org]user = hg[topsecret.server.com]host port = 50022forwardx11 = no# python 生成一个这样的文档import configparserconfig = configparser.ConfigParser()config["DEFAULT"] = {'ServerAliveInterval': '45','Compression': 'yes','CompressionLevel': '9'}config['bitbucket.org'] = {}config['bitbucket.org']['User'] = 'hg'config['topsecret.server.com'] = {}topsecret = config['topsecret.server.com']topsecret['Host Port'] = '50022'topsecret['ForwardX11'] = 'no'config['DEFAULT']['ForwardX11'] = 'yes'with open('example.ini', 'w') as configfile:config.write(configfile)# 写完了还可以再读出来import configparserconfig = configparser.ConfigParser()config.sections()file = config.read('example.ini')print(file)      # ['example.ini']title = config.sections()print(title)     # ['bitbucket.org', 'topsecret.server.com']print('bitbucket.org' in config)     # Trueprint('bytebong.com' in config)      # Falseprint(config['bitbucket.org']['User'])   # hgprint(config['DEFAULT']['Compression'])   # yestopsecret = config['topsecret.server.com']print(topsecret['ForwardX11'])           # noprint(topsecret['Host Port'])         # 50022for key in config['topsecret.server.com']:print(key)'''输出结果:host portforwardx11compressionlevelserveraliveintervalcompression'''print(config['topsecret.server.com']['Compression'])   # yes# configparser增删改查语法
import configparserconfig = configparser.ConfigParser()
config.read('i.cfg')secs = config.sections()       # 返回配置文件中的主节点
print (secs)options = config.options('bitbucket.org')
print(options)                 # 返回所有子节点信息item_list = config.items('bitbucket.org')
print(item_list)              # 列出所有子节点详细信息val = config.get('topsecret.server.com','host port')
print(val)                    # 返回单个子节点信息val2 = config.getint('topsecret.server.com','host port')
print(val2)# 删除'bitbucket.org'
sec = config.remove_section('bitbucket.org')
config.write(open('i.cfg','w'))sec2 = config.add_section('huhuan2')      # 添加主节点
config.set('huhuan2','k','1111')          # 添加子节点
config.set('huhuan','kk','2222')
config.remove_option('huhuan','kk')       # 删除子节点
config.write(open('i.cfg','w'))

八、hashlib模块

用于加密相关的操作

import hashlib# ****** md5 ******
m =hashlib.md5()
m.update(b'hello')
print(m.hexdigest())     # 16进制格式
print(m.digest())        # 2进制格式# ****** shal ******
hash = hashlib.sha1()
hash.update(b'hello')
print(hash.hexdigest())# ****** sha224 ******
hash = hashlib.sha224()
hash.update(b'hello')
print(hash.hexdigest())# ****** sha256 ******
hash = hashlib.sha256()
hash.update(b'hello')
print(hash.hexdigest())# ****** sha384 ******
hash = hashlib.sha384()
hash.update(b'hello')
print(hash.hexdigest())# ****** sha512 ******
hash = hashlib.sha512()
hash.update(b'hello')
print(hash.hexdigest())运行结果:
5d41402abc4b2a76b9719d911017c592
b']A@*\xbcK*v\xb9q\x9d\x91\x10\x17\xc5\x92'
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043

九、logging 模块

python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,logging的日志可以分为 debug(), info(), warning(), error() and critical() 5个级别。

import logging# %(message)s 日志信息
# %(levelno)s 日志级别
# datefmt  设置时间格式
# filename  设置日志保存的路径
# level=loggin.INFO意思是,把日志纪录级别设置为INFO,也就是说,只有比日志是INFO或比INFO级别更高的日志才会被纪录到文件里,
# 在这个例子, 第一条日志是不会被纪录的,如果希望纪录debug的日志,那把日志级别改成DEBUG就行了。
logging.basicConfig(format='%(asctime)s %(message)s %(levelno)s', datefmt='%m/%d/%Y %I:%M:%S %p',filename='example.log',level=logging.INFO)
logging.debug('This message should go to the log file')
logging.info('So should this')

日志格式

%(name)s Logger的名字
%(levelno)s 数字形式的日志级别
%(levelname)s 文本形式的日志级别
%(pathname)s 调用日志输出函数的模块的完整路径名,可能没有
%(filename)s 调用日志输出函数的模块的文件名
%(module)s 调用日志输出函数的模块名
%(funcName)s 调用日志输出函数的函数名
%(lineno)d 调用日志输出函数的语句所在的代码行
%(created)f 当前时间,用UNIX标准的表示时间的浮 点数表示
%(relativeCreated)d 输出日志信息时的,自Logger创建以 来的毫秒数
%(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
%(thread)d 线程ID。可能没有
%(threadName)s 线程名。可能没有
%(process)d 进程ID。可能没有
%(message)s 用户输出的消息
# 对于等级:CRITICAL = 50ERROR = 40WARNING = 30INFO = 20DEBUG = 10NOTSET = 0

Python 使用logging模块记录日志涉及四个主要类:

logger提供了应用程序可以直接使用的接口;

handler将(logger创建的)日志记录发送到合适的目的输出;

filter提供了细度设备来决定输出哪条日志记录;

formatter决定日志记录的最终输出格式。

logger :

每个程序在输出信息之前都要获得一个Logger。Logger通常对应了程序的模块名,比如聊天工具的图形界面模块可以这样获得它的Logger: LOG=logging.getLogger(”chat.gui”)

而核心模块可以这样: LOG=logging.getLogger(”chat.kernel”)

Logger.setLevel(lel):指定最低的日志级别,低于lel的级别将被忽略。debug是最低的内置级别,critical为最高

Logger.addFilter(filt)、Logger.removeFilter(filt):添加或删除指定的filter

Logger.addHandler(hdlr)、Logger.removeHandler(hdlr):增加或删除指定的handler

Logger.debug()、Logger.info()、Logger.warning()、Logger.error()、Logger.critical():可以设置的日志级别

handler

handler

对象负责发送相关的信息到指定目的地。Python的日志系统有多种Handler可以使用。有些Handler可以把信息输出到控制台,有些Logger可以把信息输出到文件,还有些 Handler可以把信息发送到网络上。如果觉得不够用,还可以编写自己的Handler。可以通过

addHandler()方法添加多个多handler

Handler.setLevel(lel):指定被处理的信息级别,低于lel级别的信息将被忽略

Handler.setFormatter():给这个handler选择一个格式

Handler.addFilter(filt)、Handler.removeFilter(filt):新增或删除一个filter对象

每个Logger可以附加多个Handler。接下来我们就来介绍一些常用的Handler:

  1. logging.StreamHandler
    使用这个Handler可以向类似与sys.stdout或者sys.stderr的任何文件对象(file object)输出信息。它的构造函数是:
    StreamHandler([strm])
    其中strm参数是一个文件对象。默认是sys.stderr

  2. logging.FileHandler
    和StreamHandler类似,用于向一个文件输出日志信息。不过FileHandler会帮你打开这个文件。它的构造函数是:
    FileHandler(filename[,mode])
    filename是文件名,必须指定一个文件名。
    mode是文件的打开方式。参见Python内置函数open()的用法。默认是’a’,即添加到文件末尾。

  3. logging.handlers.RotatingFileHandler
    这个Handler类似于上面的FileHandler,但是它可以管理文件大小。当文件达到一定大小之后,它会自动将当前日志文件改名,然后创建 一个新的同名日志文件继续输出。比如日志文件是chat.log。当chat.log达到指定的大小之后,RotatingFileHandler自动把 文件改名为chat.log.1。不过,如果chat.log.1已经存在,会先把chat.log.1重命名为chat.log.2。。。最后重新创建 chat.log,继续输出日志信息。它的构造函数是:
    RotatingFileHandler( filename[, mode[, maxBytes[, backupCount]]])
    其中filename和mode两个参数和FileHandler一样。
    maxBytes用于指定日志文件的最大文件大小。如果maxBytes为0,意味着日志文件可以无限大,这时上面描述的重命名过程就不会发生。
    backupCount用于指定保留的备份文件的个数。比如,如果指定为2,当上面描述的重命名过程发生时,原有的chat.log.2并不会被更名,而是被删除。

  4. logging.handlers.TimedRotatingFileHandler
    这个Handler和RotatingFileHandler类似,不过,它没有通过判断文件大小来决定何时重新创建日志文件,而是间隔一定时间就 自动创建新的日志文件。重命名的过程与RotatingFileHandler类似,不过新的文件不是附加数字,而是当前时间。它的构造函数是:
    TimedRotatingFileHandler( filename [,when [,interval [,backupCount]]])
    其中filename参数和backupCount参数和RotatingFileHandler具有相同的意义。
    interval是时间间隔。
    when参数是一个字符串。表示时间间隔的单位,不区分大小写。它有以下取值:
    S 秒
    M 分
    H 小时
    D 天
    W 每星期(interval==0时代表星期一)
    midnight 每天凌晨

import logginglogger = logging.getLogger('TEST_LOG')    # 获得一个Logger
logger.setLevel(logging.DEBUG)            # 设置日志级别ch = logging.StreamHandler()            # logging.StreamHandler这个Handler可以向类似与sys.stdout或者sys.stderr的任何文件对象(file object)输出信息。
ch.setLevel(logging.DEBUG)fh = logging.FileHandler("access.log")  # 用于向一个文件输出日志信息。不过FileHandler会帮你打开这个文件
fh.setLevel(logging.WARNING)formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')  # 设置日志记录的最终输出格式ch.setFormatter(formatter)
fh.setFormatter(formatter)# 添加ch,fh到logger
logger.addHandler(ch)
logger.addHandler(fh)logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')

文件自动截断实例:

import logging
from logging import handlerslogger = logging.getLogger(__name__)
log_file = "timelog.log"
fh = handlers.RotatingFileHandler(filename=log_file,maxBytes=10,backupCount=3)
#fh = handlers.TimedRotatingFileHandler(filename=log_file,when="S",interval=5,backupCount=3)formatter = logging.Formatter('%(asctime)s %(module)s:%(lineno)d %(message)s')
fh.setFormatter(formatter)logger.addHandler(fh)logger.warning("test1")
logger.warning("test12")
logger.warning("test13")
logger.warning("test14")

十、subprocess模块(待定)

十一、json & pickle 模块

用于序列化的两个模块json,用于字符串 和 python数据类型间进行转换
pickle,用于python特有的类型 和 python的数据类型间进行转换
Json模块提供了四个功能:dumps、dump、loads、loadpickle模块提供了四个功能:dumps、dump、loads、loadimport pickledate = {'k1':'123','k2':'hello'}str = pickle.dumps(date)    # pickle.dumps 将数据通过特殊的形式转换为只有python认识的字符串
print(str)with open('result.pk','w') as fp:  # pickle.dump 将数据通过特殊的形式转换为只有python认识的字符串并写入文件pickle.dump(date,fp)import jsonstr1 = json.dumps(date)     # json.dumps 将数据通过特殊形式转换为所有程序语言都认识的字符串
print(str1)with open('result1.json','w') as fp:  #json.dump 将数据通过特殊的形式转换为只有python认识的字符串并写入文件json.dump(date,fp)```

Python自学——python的常用模块相关推荐

  1. Python基础语法(五)—常用模块和模块的安装和导入

    Python基础语法(五)-常用模块的使用和模块的安装和导入,本文介绍的Python模块有:os.sys.time.datetime.random.pickle.json.hashlib.shutil ...

  2. python复制文件shutil_Python常用模块——文件复制模块shutil

    Python常用模块--文件复制模块shutil shutil模块 高级的文件.文件夹.压缩包处理模块 shutil.copyfileobj(fsrc, fdst) 将文件内容拷贝到另一个文件中 im ...

  3. python dcf估值_Python 常用模块

    本节内容 模块介绍 os 模块 sys 模块 time & datetime模块 random 模块 json & picle shutil 模块 shelve 模块 xml 模块 c ...

  4. python自学-Python 应该怎么学?

    0714更新: 之前说过骆昊 (jackfrued) 的"从新手到大师"的百天之路!今天给大家分享一个主学习路线的干货图谱,话不多说,直接上图! 这个图谱是按照[专业基础][数据分 ...

  5. Python之几种常用模块

    模块 注意事项: 所有的模块导入都应该尽量往上写内置模块扩展模块自定义模块 模块不会重复被导入 : sys.moudles 从哪儿导入模块 : sys.path import import 模块名模块 ...

  6. Python 之路 Day5 - 常用模块学习

    模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configparser has ...

  7. python学习笔记之常用模块用法分析

    内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像函数一样调用 repr(obj) 得 ...

  8. Python学习笔记之常用模块总结,持续更新...

    阅读目录 1. 时间模块--datetime 2. 文件目录操作模块--os 很多人学习python,不知道从何学起. 很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手. 很多已经 ...

  9. Python爬虫原理与常用模块——数据提取与清洗策略

    1 正则表达式 1.1概念 世界上信息非常多,而我们关注的信息有限.假如我们希望只提取出关注的数据,此时可以通过一些表达式进行提取,正则表达式就是其中一种进行数据筛选的表达式. 正则表达式(Regul ...

最新文章

  1. 苹果发布第三财季财报 盘后股价上涨5%
  2. Maven学习总结(二)——Maven项目构建过程练习
  3. UA MATH564 概率论VI 数理统计基础3 卡方分布上
  4. 计算机系统崩溃重新装机,当计算机系统崩溃时如何用U盘重新安装Win7系统
  5. 麒麟970怎么升级鸿蒙系统,华为这些手机无法升级鸿蒙系统,搭载麒麟970,只能遗憾错过...
  6. printf 和sprintf
  7. 省队集训Day3 tree
  8. es6箭头函数(墙裂推荐)
  9. 使用VS2012内建的C++测试架构进行单元测试
  10. 字符串匹配的KMP算法(转)
  11. java国王毒酒答案,换换脑子500桶酒国王用囚犯找毒酒答案-500桶酒其中1桶是毒酒找毒酒答案最新版【附公式详解】-东坡下载...
  12. 工作总结 项目中如何处理重复提交问题
  13. 一本通网站练习源码(待完善)
  14. mysql统计一张表中条目个数的方法
  15. telegram bots 开发者文档 简介
  16. SSM毕设项目车辆维修管理系统m97p7(java+VUE+Mybatis+Maven+Mysql)
  17. 2017年国家公务员考试行测错题集(省级)
  18. windows 无法停止ics_Windows10系统不能启动ICS服务致无法连接WiFi热点的三种解决方法...
  19. c#之List深度复制
  20. Hadoop数据迁移工具DistCp

热门文章

  1. springcloud hystrix实战(二)
  2. 搭建推荐系统所需要的材料
  3. 2021年度移动广告流量观察白皮书
  4. 2020年美妆行业内容营销报告
  5. memset 结构体内指针_数据结构之线性表应用——内存管理
  6. 如何绘制逻辑图 — 9.模型的分类
  7. 如何绘制逻辑图— 4. 要素的属性:黑盒与白盒
  8. oracle 触发器
  9. 【VB.NET】实验 编写个人信息管理系统
  10. 【Python】处理 from sklearn.externals import joblib 报错问题