模块十 python标准库

OS

mkdir 创建文件夹

import os
os.mkdir("test")

listdir 当前目录下有那些文件

import os
print(os.listdir("/"))

removedir  删除文件

import os
os.removedirs("test")

getcwd 展示路径

import os
print(os.getcwd())

新建b/test1.txt

import os
if not os.path.exists("b"):
    os.mkdir("b")
if not os.path.exists("b/test1.txt"):
    f = open("b/test1.txt","w")
    f.write("hello,nihaoya")
    f.close()

 time

 官网:python.org

import  time

print(time.asctime())  #国际时间

time.time

import  time

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

  

import  time
print(time.localtime())#元祖的形式,
格式:
print(time.strftime("%Y-%m-%d %H:%M:%S", 元祖)
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

 获取两天前的时间

import  time

#获取两天前现在的时间
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.localtime()))

作业:

三天后的时间

import  time
now_time = time.time()
three_days = now_time + 60*60*24*3
time1 = time.localtime(three_days)
print(time.strftime('%Y-%m-%d %H:%M:%S', time1))

urllib库

math库

import math

print(math.ceil(5.5))  #上限
print(math.floor(5.2))  #下限
import math

print(math.sqrt(36))  #开方根

 

原文地址:https://www.cnblogs.com/hantongxue/p/14299828.html