我可以在 python 中使用库抽象吗? [英] Can I use library abstractions in python?

查看:34
本文介绍了我可以在 python 中使用库抽象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:

for root, dirs, files in os.walk(rootDir):

浏览目录.都很酷.但是,我在 Windows 7 上运行,它当然具有库抽象.例如,图片库可能映射到 c:\users\mec:\users\share有什么办法可以在 python 中使用这个库抽象吗?

to navigate around directories. All cool. However, I am running on windows 7 which of course has the library abstraction. So for example the picture library might map to c:\users\me and c:\users\share Is there any way I can use this library abstraction with python?

推荐答案

除非我对这个功能的工作方式有误解(我面前实际上没有一个 Win7 框),否则你将不得不访问 WindowsShell API 以访问库.

Unless I'm wrong about how this feature works (I don't actually have a Win7 box in front of me), you will have to access the Windows Shell APIs in order to access libraries.

阅读 MSDN 杂志中的介绍库,看起来很漂亮很明显,只处理文件系统的应用程序会将库视为一个常规目录,甚至没有任何关于构成库的各种分散目录的指示.除非您总是坚持使用花哨的文件选择器对话框来获取所有路径(在这种情况下,用户会看到库,但最终总是选择一个特定的文件夹,因此您不必处理库),您必须明确使用外壳 API.

Reading Introducing Libraries from MSDN Magazine, it seems pretty clear that apps that just deal with the filesystem will see a library as just a regular directory, and not even have any indication of the various scattered directories that make up the library. Unless you always stick to the fancy file-chooser dialogs to get all paths (in which case the user sees libraries, but always ends up picking a specific folder, so you don't have to deal with libraries), you have to explicitly use the shell APIs.

我认为您想从 Windows 库 用于开发指南和 IShellLibrary 供参考.

I think you want to start at Windows Libraries for the dev guide and IShellLibrary for the reference.

这些显然是 COM API,因此您可能想要使用 win32com 从 Python 访问它们.(您可以使用 ctypes 并处理 C 风格的 COM 内容,但您真的不想这样做.)可能有人已经将这些 COM 对象包装在一个漂亮的 Python 接口中——我在快速 PyPI 和 ActiveState 搜索中没有找到任何内容,但您可能想尝试更认真的搜索.

These are obviously COM APIs, so you probably want to use win32com to access them from Python. (You could use ctypes and deal with the COM stuff C-style, but you really don't want to.) It's possible that someone has already wrapped up these COM objects in a nice Python interface—I didn't find anything in quick PyPI and ActiveState searches, but you might want to try a more serious search.

当然,您也可以使用 IronPython 并使用 .NET API 而不是本机 API.

Alternatively, of course, you could use IronPython and use the .NET APIs instead of the native ones.

这篇关于我可以在 python 中使用库抽象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆