关于python语言在win系统开发转到os系统开发的问题求助

satotroy 2020-09-07 09:08:54
各位大神好,我是小白,之前让一个实习生帮我开发了一个小模块,但是他是在windows开发的,我的电脑是苹果的,后来我就在我的苹果系统运行,结果发现运行错误,所以想问问大神,这里面怎么修改才可以匹配苹果的系统运行呢?我苹果是用pycharm运行的。

ps:我开始把源代码的第一行关于windows的删除了就能运行了,但是到了第54行调用他模块的ppt软件的就又不行了,实在编程小白。。求助。。


import win32com.client, sys 我删除了这个以后,下面在这里就报错了
import os
import math

if __name__ == '__main__':

current_address = os.path.dirname(os.path.abspath(__file__))

#--------------------用二维列表存放每个PPT的相对地址
print('---------------------------------------------------------------------------------')
print(' 各模块PPT文件信息')
print('---------------------------------------------------------------------------------')
path_list =[[0 for col in range(20)] for row in range(20)] # 创建20*20的二维列表,存放每个PPT文件的地址
module_index = 0
for parent, dirnames, filenames in os.walk(current_address):
for each_module in dirnames:
module_index = module_index + 1
# module_name[module_index] = each_module
print("module", module_index, ":", each_module)
file_index = 0
file_list = os.listdir(each_module) # 获取each_module下面的所有PPT文件的名字
for each_file in file_list:
file_index = file_index + 1
print("file", file_index, ":", each_file)
file_path = current_address + '\\' + each_module + '\\' + each_file # 每个PPT文件地址 = 代码所在文件夹 + 模块名 + 文件名
file_path = file_path.replace('\\', '/') #绝对路径转为相对路径
path_list[module_index][file_index] = file_path
# print(list[module_index][file_index])

#-----------------------用vector存放用户的选择,格式:<模块序号,文件序号>
print()
print('---------------------------------------------------------------------------------')
print(' 请按顺序输入您选择的PPT文件,输入格式为:模块序号 文件序号')
print(' 所有文件选择完毕后,请输入:0 0')
print('---------------------------------------------------------------------------------')

class Vector(object):
def __init__(self, x, y):
self.x = x
self.y = y

m = 1
n = 1
choice_list = {}
i = 1
while m > 0:
print('您选择的第', i, '个PPT文件:',end='')
m, n = map(int, input().split())
v = Vector(m, n)
choice_list[i] = v
i = i + 1
# print(choice_list)

#-----------------------遍历choice,合并PPT
Application = win32com.client.Dispatch("PowerPoint.Application")
Application.Visible = True
# 创建一个新的空白PPT对象
new_ppt = Application.Presentations.Add()

for each_choice in choice_list:
# print(each_choice)
# print(choice_list[each_choice])
# print(choice_list[each_choice].module())
file_path = path_list[choice_list[each_choice].x][choice_list[each_choice].y]
exit_ppt = Application.Presentations.Open(file_path)
page_num = exit_ppt.Slides.Count
exit_ppt.Close()
num = new_ppt.Slides.InsertFromFile(file_path, new_ppt.Slides.Count, 1, page_num)

# new_ppt.SaveAs(r'D:\python作业集\合并PPT\new_ppt.pptx')
Presentation.Save()
Application.Quit()

...全文
146 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianfang 2020-09-10
  • 打赏
  • 举报
回复
<span style="color: #FF0000;"> 这些是字体颜色控制,不是标准的python代码 删除就可以用了
chuifengde 2020-09-08
  • 打赏
  • 举报
回复
pip install python-pptx
庸了个白 2020-09-08
  • 打赏
  • 举报
回复
另外一提,python操作ppt已经不是冷门了,是基本没什么用处,上不了生产力层次,所以并没有存在什么好用的包。 不过呢真要跨平台这么搞,还真有办法。 每一个ppt,doc或者是word,实质上都是这样的压缩包(你可以把 .ppt改成 .rar 就可以看到了) 然后找个实习生,让他用python更改里面的文字,保存后再改回去 .ppt,效果是一样的。 有点绕,但基本是搬砖,没什么技术含量
庸了个白 2020-09-08
  • 打赏
  • 举报
回复
win32 是windows的接口,系统完全不一样。在mac上肯定用不了。 没听过mac os的接口。 mac一般不都有双系统的么。干脆换成win执行了。
snjaychou 2020-09-08
  • 打赏
  • 举报
回复
没用过macos,不是很清楚原因。不过可以猜一下,win32是Windows的接口,在macOS上应该是无法调用的。

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧