# Python统计多个Powerpoint文件中幻灯片总数量

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

from random import 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)

641 篇文章73 人订阅

0 条评论

## 相关文章

1230

### Java项目经验——程序员成长的关键

Java就是用来做项目的！Java的主要应用领域就是企业级的项目开发！要想从事企业级的项目开发，你必须掌握如下要点： 1、掌握项目开发的基本步骤 2、具备极强的...

1220

1053

5127

9950

2565

2863

### 成为优秀Java程序员的10大技巧

Java程序员有许多应遵循的守则或最佳实践方式。本文概述了每个开发者最应该遵循的10条守则或戒律，如果不遵循它们，将会导致灾难性后果。

7831

### 三七互娱秋招提前批 java服务端

我是在6月5号参加了三七互娱的秋招的web后端线上笔试,第二天又参加了java服务端的线上笔试,之后去三七大楼参加open day,然后面试时一面,二面...

1251

4176