美文网首页
python-(time、IO)

python-(time、IO)

作者: 不知名的二狗 | 来源:发表于2019-08-25 22:32 被阅读0次

time

import time
a = time.time()
b = time.ctime()
c = time.strftime("%b %d %Y %H:%M:%S")
print(a)
print(b)
print(c)

执行结果

1566743022.071017
Sun Aug 25 22:23:42 2019
Aug 25 2019 22:23:42

IO

open读文件

第一种(需要close)

# 文件读取
f_read = open('1.txt')
fp = f_read.read()
print(fp)
f_read.close()
# 文件写入
f_wri = open("1.txt","a")
f_wri.write("hello world")
f_wri.close()

第二种(不需要关闭)

with open("1.txt",'r') as fp:
    a = fp.read()
    print(a)

相关文章

网友评论

      本文标题:python-(time、IO)

      本文链接:https://www.haomeiwen.com/subject/tptlectx.html