摘要:
import shutil, os, zipfile # 复制、移动、改名、删除文件与文件夹 #shutil.copy('e:\\111\\key.txt', 'd:\\111\\') # copy文件 #shutil.copytree('e:\\111', 'd:\\111\\aaa') # co 阅读全文
摘要:
import pprint#格式化打印message = 'It was a bright cold day in April, and the clocks were striking thirteen.'count = {}for character in message: count.setd 阅读全文
摘要:
import shelve# shelve_demo.py 持久性字典:Python对象的持久化# 键值对形式, 将内存数据通过文件持久化, 值支持任何pickle支持的Python数据格式# 与pickle的主要区别是键值对方式, 并且在目录下生成三个文件class Person(object): 阅读全文
摘要:
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' 阅读全文