gpt4 book ai didi

Python - 使用参数创建快捷方式

转载 作者:太空狗 更新时间:2023-10-30 02:47:02 24 4
gpt4 key购买 nike

使用 win32com.client,我试图在文件夹中创建一个简单的快捷方式。但是我想要有参数的快捷方式,除非我不断收到以下错误。

Traceback (most recent call last):
File "D:/Projects/Ms/ms.py", line 153, in <module>
scut.TargetPath = '"C:/python27/python.exe" "D:/Projects/Ms/msd.py" -b ' + str(loop7)

File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 570, in __setattr__
raise AttributeError("Property '%s.%s' can not be set." % (self._username_, attr))
AttributeError: Property '<unknown>.TargetPath' can not be set.

我的代码如下所示。我尝试了多种不同的变体,但似乎无法正确处理。我做错了什么?

ws = win32com.client.Dispatch("wscript.shell")
scut = ws.CreateShortcut("D:/Projects/Ms/TestDir/testlink.lnk")
scut.TargetPath = '"C:/python27/python.exe" "D:/Projects/Ms/msd.py" -b 0'
scut.Save()

最佳答案

您的代码对我来说没有错误。 (Windows XP 32 位、Python 2.7.5、pywin32-216)。

(我稍微修改了您的代码,因为 TargetPath 应该只包含可执行路径。)

import win32com.client
ws = win32com.client.Dispatch("wscript.shell")
scut = ws.CreateShortcut('run_idle.lnk')
scut.TargetPath = '"c:/python27/python.exe"'
scut.Arguments = '-m idlelib.idle'
scut.Save()

当我尝试跟随(将列表分配给 Arguments 属性时),我遇到了与您类似的 AttributeError。

>>> scut.Arguments = []
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 570, in __setattr__
raise AttributeError("Property '%s.%s' can not be set." % (self._username_, attr))
AttributeError: Property '<unknown>.Arguments' can not be set.

关于Python - 使用参数创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17586599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com