2015-09-05 77 views
0

-Update在自下而上winshell.shortcut(父),得到「模塊沒有屬性‘快捷方式’

pywin32 &沒有明顯的錯誤,但 下面的測試代碼(從這裏的示例中提取winshell安裝: winshell examples):

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窗口上的輸出被格式化爲代碼,這顯然不是。好奇爲什麼。它確實包含包含的代碼片段,但這不是一回事。

  • 更新 - 大部分在文檔中示出的其它方法是不是在目錄(winshell)輸出(例如,文件的方法,如COPY_FILE):

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

回答

0

問題解決經過@Maksim Yegorov的一些協助。問題是安裝過程會自動將winshell文件放入 .../Lib/site-packages/winshell。
然而,對於示例代碼的工作,他們需要在 ... /庫/站點包 如果他們是在自己的文件夾,然後代替
from winshell import shortcut winshell.py其 from winshell.winshell import shortcut和線26需要以類似方式修改爲 from winshell.__winshell_version__ import __VERSION__

winshell文檔可能需要澄清,以避免這種情況。