Python统计多个Powerpoint文件中幻灯片总数量
来源:互联网 发布:傻瓜app编程软件 编辑:程序博客网 时间:2024/05/16 15:52
晚上吃饭时突然想知道自己做了多少页《Python程序设计》系列教材的配套PPT,于是就有了下面的代码,这套PPT综合了《Python程序设计基础》(ISBN:9787302410584)、《Python程序设计(第2版)》(ISBN:9787302436515)和《Python可以这样学》(ISBN:9787302456469)以及将要出版的《Python程序设计开发宝典》4本书的内容,部分内容比书上详细,有的地方不如书上详细,主要是上课用,几本书重点介绍Python 3.4.x、3.5.x、3.6.x的语法和应用,全套课件均已免费分享。
import os
import os.path
import win32com
import win32com.client
total = 0
def pptCount(path):
global total
for subPath in os.listdir(path):
subPath = os.path.join(path, subPath)
if os.path.isdir(subPath):
pptCount(subPath)
elif subPath.endswith('.ppt'):
print(subPath)
powerpoint = win32com.client.Dispatch('PowerPoint.Application')
powerpoint.Visible = 1
ppt = powerpoint.Presentations.Open(subPath)
win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
total += ppt.Slides.Count
powerpoint.Quit()
pptCount('F:\\教学课件\\Python程序设计(第二版)')
print(total)
运行结果显示:
pptx肿么办?
首先:
pip install python-pptx
然后:
>>> import pptx
>>> p = pptx.Presentation('f:\\1.pptx')
>>> len(p.slides)
3
另外,关于昨天发的文章再补充一下,原文参见Python计算序列中数字最大差值(美团2016校招笔试题)
昨天发文之后立刻有上海交大李老师和读者朋友zhouyonghaha指出算法效率太低,其实一次循环就可以,开始我还不太明白,想了一下果然如此,于是有了下面的高效代码,算作一个补充:
from randomimport randrange
def maxDifference2(lst):
diff = -float('inf')
minCurrent = lst[0]
for value in lst[1:]:
if value < minCurrent:
minCurrent = value
else:
t = value-minCurrent
if t > diff:
diff = t
result = (minCurrent, value)
return result
for _ in range(10):
print('='*20)
lst = [randrange(1,100) for _ in range(20)]
print(lst)
print(maxDifference2(lst))
运行结果显示:
====================
[22, 20, 32, 66, 22, 74, 74, 31, 88, 94, 18, 35, 47, 75, 14, 83, 44, 57, 53, 95]
(14, 95)
====================
[60, 15, 46, 36, 93, 45, 92, 56, 36, 57, 87, 80, 47, 4, 72, 18, 79, 32, 35, 1]
(15, 93)
====================
[4, 40, 92, 99, 87, 14, 52, 55, 35, 52, 1, 53, 50, 46, 39, 53, 29, 8, 45, 32]
(4, 99)
====================
[41, 53, 52, 47, 93, 67, 18, 38, 77, 12, 87, 42, 43, 2, 16, 32, 20, 54, 33, 72]
(12, 87)
====================
[68, 41, 29, 33, 23, 81, 5, 41, 17, 54, 69, 29, 90, 10, 57, 88, 14, 30, 69, 81]
(5, 90)
====================
[1, 46, 27, 47, 68, 44, 89, 15, 2, 10, 32, 90, 45, 79, 33, 99, 21, 61, 79, 21]
(1, 99)
====================
[64, 58, 97, 65, 15, 13, 35, 86, 25, 58, 26, 51, 65, 14, 6, 98, 90, 25, 98, 42]
(6, 98)
====================
[55, 14, 18, 57, 40, 27, 55, 93, 21, 16, 48, 32, 93, 69, 50, 13, 89, 98, 59, 40]
(13, 98)
====================
[11, 19, 17, 96, 21, 25, 74, 71, 78, 8, 49, 58, 57, 36, 72, 56, 83, 93, 41, 65]
(11, 96)
====================
[48, 95, 56, 44, 42, 40, 83, 86, 82, 50, 73, 88, 98, 52, 28, 60, 33, 17, 68, 59]
(40, 98)
- Python统计多个Powerpoint文件中幻灯片总数量
- Python批量导出多个PPT/PPTX文件中每个幻灯片为独立JPG图片
- 根据数据表中数据,生成Powerpoint幻灯片
- 根据数据表中数据,生成Powerpoint幻灯片
- powerpoint中使幻灯片连续播放
- 用Powerpoint打开ppt文件出现提示:"PowerPoint无法显示文件中某些幻灯片中的文字、图像或对象,“xx.ppt”解决办法
- 乐享PowerPoint!5个PPT成就幻灯片达人
- PowerPoint如何复制幻灯片
- 【php】统计goods_category表中各分类下商品的总数量
- Python的MapReduce调用及多输入文件的使用(统计url的点击量)
- 在一张纸上打印多幅Powerpoint幻灯片
- 【Python】以不定条件下兔子总数计算为例-Python中对数量规律问题的思考与延展
- 总数统计
- Hibernate中使用count(*)统计记录总数
- PowerPoint 幻灯片 PPT 进度条 制作
- 用好PowerPoint的“重用幻灯片”
- 自定义PowerPoint切换幻灯片按钮
- sql根据多个不同字段进行分组,并统计总数,求和。tp求和,分页
- Unity3D学习:制作背包换装备UI
- HDU 1171 Big Event in HDU(背包)
- 跟我一起写Makefile:MakeFile介绍
- 使用Python求取前100组勾股数
- 去掉LINUX系统对用户的内存大小和文件句柄限制等限制
- Python统计多个Powerpoint文件中幻灯片总数量
- 【CS231n】Lecture 6:Training Neural Networks,Part 2
- WordPress Exploit-4-6 RCE CVE-2016-10033
- 自定义可刷新的LIstView
- C# 餐桌项目增加、修改、删除、查询(登录注册界面)
- 二叉树三种遍历方式之循环
- 剑指offer-49.把字符串转换成整数
- finished with non-zero exit value 1
- HDU2546 饭卡(背包)