栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python标准库

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python标准库

Python标准库常见模块:
操作系统相关:OS
时间与日期:time,datetime
科学计算:math
网络请求:urllib

OS模块

os模块主要是针对文件,目录的操作
常用方法:
os.mkdir() 创建目录
os.removedirs() 删除文件
os.getcwd() 获取当前目录
os.path.exists(dir or file)判断文件或者目录是否存在

import os

#os.makedirs("testdir")  #创建目录

#打印有哪些文件
print(os.listdir("./"))
# os.removedirs("testdir")  #删除目录
print(os.getcwd()) #打印当前路径

print(os.path.exists("b"))
if not os.path.exists("b"):
    os.mkdir("b")
if not os.path.exists("b/test.txt"):
    f=open("b/test.txt","w")
    f.write("hello,os using")
    f.close()

time 模块
获取时间以及时间格式的模块
import time
time常用的方法:

import time

print(time.asctime())  #国外时间格式

print(time.time())  #时间戳

print(time.localtime()) #时间格式转换为元组

print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())) #转换时间格式

#获取两天前的时间
two_befor_time=time.time()-60*60*24*2
time_tumple=time.localtime(two_befor_time)
print(time.strftime("%Y-%m-%d %H:%M:%S", time_tumple))


urllib库

math库

import math

print(math.ceil(5.5))  #大于或等于这个最小整数

print(math.floor(5.5)) #小于这个值的整数

print(math.sqrt(9)) #开平方
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/529919.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号