银行卡解冻
import time
import os
dj = "2019-03-26 16:03:20"
jd = time.mktime(time.strptime(dj,"%Y-%m-%d %H:%M:%S"))
# print("解冻时间点的秒数为:%f秒"%jd)
while True:
dq = time.time()
# print("当前时间为:%f秒"%dq)
sy = jd - dq
# print("距离解冻还剩:%f秒"%sy)
a = sy%60
b = sy//60%60
c = sy//60//60%24
d = sy//60//60//24
os.system("cls")
print("剩余解冻时长为:%d天,%d小时,%d分,%d秒"%(d,c,b,a))
time.sleep(1)
结果为:
文件读取
a = open("D:\\nihaoma\\nihao.txt","r")
x = a.read()
print(x)
a.close()
结果为:
读取多行
a = open("D:\\nihaoma\\nihao.txt")
x = a.readline() #读取一行
while len(x)>0: #循环读多行
print(x)
x = a.readline()
a.close()
读取所有行
a = open("D:\\nihaoma\\nihao.txt")
x = a.readlines()
print(x)
for line in x:
print(line)
a.close()
取消换行\n
a = open("D:\\nihaoma\\nihao.txt")
x = a.readlines()
print(x)
for line in x:
if line[-1]=="\n":
print(line[:-1])
else:
print(line)
a.close()
结果为:
文件改写
a = open("D:\\nihaoma\\nihao1.txt","w")
b = "你还好吗"
a.write(b)
a.close()
文件内容增加
程序每执行一次,就多一次结果。
a = open("D:\\nihaoma\\nihao2.txt","a")
b = "1234"
a.write(b)
a.close()
指针
a = open("D:\\nihaoma\\nihao2.txt","r")
x = a.read(4)
print(x,a.tell()) #tell告诉我现在的位置长度坐标
y = a.read(5)
print(y)
a.seek(3,0) #重新设置指针位置,第一个参数是位置的偏移量,
#第二个参数是从哪个地方开始,0代表开头,1是当前位置,2是结尾
z=a.read(3) #截取第三位后面的3个元素
print(z)
a.close()
重命名和删除
#重命名
import os
os.rename("D:\\nihaoma\\nihao3.txt","D:\\nihaoma\\nihao2.txt")
os.rename("D:\\nihaoma\\nihao1.txt","D:\\nihaoma\\nihao4.txt")
#删除
os.remove("D:\\nihaoma\\nihao2.txt")
path = os.getcwd() #输出当前目录
print(path)
os.mkdir("a\\b\\c",0x777) #创建文件#124 执行 写 读
b = os.path.exists("D:\\nihaoma\\nihao.txt") #查找是否存在
print(b)
b = os.path.exists("a\\e") #判断当前目录的文件是否包含
print(b)