摘要:
import pickle# 序列化 用于对Python对象进行序列化和反序列化的二进制协议f = open("pickle.txt", "wb+")lists = [123, "中文", [456]]strs = "字符串"num = 123# 写入pickle.dump(lists, f) # 阅读全文
摘要:
import os path = os.getcwd() # 获取当前目录print("路径: {}".format(path)) # 路径: E:\python\练习\笔记dirname = os.path.dirname(path) # 获取文件夹名print("文件夹名为: {}".forma 阅读全文
摘要:
import osimport signal # 执行命令dirs = os.popen("dir").read()print(dirs)# 打印目录树dirs_info = os.scandir()for info in dirs_info: print("文件名: {}, 路径: {}, ino 阅读全文
摘要:
import calendarimport timecalen_text = calendar.TextCalendar()# 打印月历calen_text.prmonth(2017, 5, w=0, l=0)# 打印年历calen_text.pryear(2017, w=2, l=1, c=6, 阅读全文
摘要:
import datetime import time datetime_dt = datetime.datetime.today() # 获取当前日期和时间, 2017-10-26 10:03:28.693198datetime_str = datetime_dt.strftime("%Y/%m/ 阅读全文
摘要:
import timedef time_demo(): curtime = time.time() # 获取当前时间戳, 1508982743.220433 time_str = time.ctime(curtime) # 转为string格式, 'Thu Oct 26 09:52:23 2017' 阅读全文