代码拉取完成,页面将自动刷新
import os
import binascii
from docx import Document
from pyDes import des, CBC, PAD_PKCS5
def mkdir(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
print(path + ' 创建成功')
return True
else:
print(path + ' 目录已存在')
return False
def mkfile(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
file= open(path,'w')
print(path + ' 创建成功')
file.close()
print("文件已关闭")
return True
else:
print(path + ' 文件已存在')
return False
def write(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
mkfile(path)
write(path)
else:
file = open(path, 'a')
what = input("请输入您想写入的文字:\n")
file.write(what+'\n')
print('写入成功')
file.close()
print("文件已关闭")
def read(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
mkfile(path)
read(path)
else:
file = open(path, 'r')
print(file.read())
file.close()
print("文件已关闭")
def word(path):
Docx = Document()
Docx.add_heading("姓名 学号 性别 班级 成绩 健康")
Docx.add_heading("张三 20190001 男 201900 99 健康")
Docx.add_heading("李四 20190002 男 201900 98 健康")
Docx.save(path)
document = Document(path)
for paragraph in document.paragraphs:
print(paragraph.text)
def des_encrypt():
KEY = 'areyouok'
def des_descrypt(s):
secret_key = KEY
iv = secret_key
k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5)
de = str(de)
Docx = Document()
Docx.add_paragraph(de)
Docx.save("C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\解密文件.doc")
Docx = Document()
Docx.add_heading("This is my word!")
Docx.save("C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\明文.doc")
path = "C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\明文.doc"
document = Document(path)
for paragraph in document.paragraphs:
s = paragraph.text
secret_key = KEY
iv = secret_key
k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
en = k.encrypt(s, padmode=PAD_PKCS5)
en = binascii.b2a_hex(en)
des_descrypt(en)
en = str(en)
Docx = Document()
Docx.add_paragraph(en)
Docx.save("C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\密文.doc")
def exel():
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
path = "C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\20181221.doc"
document = Document(path)
i=-1
for paragraph in document.paragraphs:
i+=1
k=-1
list=paragraph.text.split();
for j in list:
k+=1
ws.write(i, k, j)
wb.save('C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\20181221.xls')
if __name__ == "__main__":
mkpath = "C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812"
mkdir(mkpath)
filename = "C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\20181221.txt"
mkfile(filename)
# write(filename)
read(filename)
word("C:\\Users\\misaka\\Desktop\\北京电子科技学院\\python\\1812\\20181221.doc")
des_encrypt()
exel()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。