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

Python标准库&第三方库

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

Python标准库&第三方库

import os

import time

import urllib.request

import math

# 标准库有 os、time、urllib、request

import requests
# 第三方库有很多 requests、pytest、可以使用pip install xxx进行安装第三方库
r = requests.post("http://httpbin.org/post",data={"key":"value"})
# print(r.status_code)
#
# print(r.encoding + "查看编码")
# r.encoding = "utf-8"
print(r.text + "查看返回结果")
print(r.raw)




# os.mkdir("a.txt")
# os.removedirs("a.txt")
# 打印当前所有的目录
print(os.listdir("./"))
# 获取当前的路径
print(os.getcwd())

print(os.path.exists("b"))
# if not os.path.exists("b"):# 判断当前目录下是否存在文件夹b 若不存在则创建文件夹b
#     os.mkdir("b")
# if not os.path.exists("b/a.txt"):
#     open("b/a.txt","w").write("qwer")

# 国外的时间格式
print(time.asctime())
# 时间戳
print(time.time())
# 将时间戳转化成时间的元组
print(time.localtime())
# 将时间戳转化成带格式的时间
print(time.strftime(format("%Y-%m-%d %H:%M:%S")))

# 获取两天前的当前时间
now_time = time.time()
two_day_before = now_time - 60*60*24*2
time_tuple = time.localtime(two_day_before)# 转成元组
print(time.strftime("%Y-%m-%d %H:%M:%S",time_tuple))# 格式化时间

# 打开网址
response = urllib.request.urlopen("http://www.baidu.com")
print(response.status)
print(response.headers)


print("-=======================math库===================-")

# 向上取最小的正数
print(math.ceil(6.7))
# 向下取最小的正数
print(math.floor(6.8))
# 取平方根
print(math.sqrt(26))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/861275.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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