python - 重命名 pdf 重命名 pdf 文件及其文本内容在特定位置
问题描述
我找不到使用该enumerate
功能重命名文件的方法。例子:
for position, line in enumerate(pdf_text):
lines_to_read = [1280,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291]
if position in lines_to_read
print(line,end="")
# I can print the text sequence at specific conditions
pdf_file_obj.close()
# but i've not success for use the print output as file name
os.rename(fullpath,+ "??" + ".pdf")
如何转换输出中的字符串以将其用作文件名?
解决方案
我使用链式正则表达式解决了它。
我谢谢大家
for index in re.finditer("SHERAZ0101", pdf_text):
#oc_ext = pdf_text[index.start()+506:index.start()+531]
doc_ext = pdf_text[index.end()+488:index.end()+521] +pdf_text[index.end()+471:index.end()+477]
doc_num = "" + doc_ext.replace('\n\n',"").replace('/',"-").replace('SPECI',"").replace(":","").replace(" ", "").replace(" .pdf",".pdf")
pdf_file_obj.close()
print(doc_ext)
# rename the pdf based on the information in the pdf
os.rename(fullpath, rename_folder + "\\" + doc_num + ".pdf")
推荐阅读
- python - AttributeError:“NoneType”对象在网络抓取工具中没有属性“findAll”
- javascript - 如果不存在边界,则传单错误坐标
- python - ValueError:采样器选项与 shuffle pytorch 互斥
- javascript - 如何在反应中为单个页面中的多个组件进行嵌套路由
- vue.js - 在 Vue 中使用 v-for 循环,如何只显示重复值的一次迭代?
- python - 如果未在原始字符串中给出路径和文件名,则 PIL Image.open 上的“[Errno 13] Permission denied”
- python - 如何计算熊猫中行的百分比?
- spring-boot - 如何设计一个 Springbatch 作业,从 DB 中批量获取记录并并行运行多个处理器和写入器
- c++ - 使用 WinApi / c++ 修改 Windows 资源管理器工具栏
- python - 从网站中提取书名和作者 - Python 3