0

-在底部更新-

pywin32 & winshell 安装时没有明显错误,但测试代码如下(从此处的示例中提取:winshell 示例):

import winshell
parent = 'H:\MUSIC\TESTC\TESTTB.lnk'  # target is H:\MUSIC\TESTB
with winshell.shortcut(parent) as link:
    print(link.path)

产生了这个结果:

> Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Traceback (most recent call last):
  File "C:\Python33\MyScripts\Audio\shortcut2.py", line 3, in <module>
    with winshell.shortcut(parent) as link:
AttributeError: 'module' object has no attribute 'shortcut'
>>> 

事实上,winshell 安装可能不正确 - 我应该寻找什么?

PS:系统似乎要求将 python 窗口上的输出格式化为代码,而这显然不是。很好奇为什么。它确实包含一个代码片段,但那不是一回事。

  • 更新 - 文档中显示的大多数其他方法不在 dir(winshell) 输出中(例如,文件方法,如 copy_file):

    >>> dir(winshell)
    >>> ['__RELEASE__', '__VERSION__', '__builtins__',  
    >>> '__cached__', '__doc__', '__file__', 
    >>> '__initializing__', '__loader__', '__name__', 
    >>> '__package__', '__path__']
    
4

1 回答 1

0

在@Maksim Yegorov的帮助下问题解决了。问题是安装过程会自动将 winshell 文件放入 .../Lib/site-packages/winshell。
但是,要使示例代码正常工作,它们需要位于 .../Lib/site-packages 如果它们要位于自己的文件夹中,则需要以类似的方式修改 winshell.py 的第 26 行 而不是
from winshell import shortcutfrom winshell.winshell import shortcutfrom winshell.__winshell_version__ import __VERSION__

可能需要澄清 winshell 文档以避免这种情况。

于 2015-09-06T07:04:58.490 回答