gpt4 book ai didi

python - VS 代码和 Python 中自动化对象的自动完成

转载 作者:太空狗 更新时间:2023-10-29 20:27:00 26 4
gpt4 key购买 nike

我安装了适用于 Windows 的 Python 扩展。在 PythonWin IDE 中,我可以获得 Automation 对象(特别是使用 win32com.client.Dispatch 创建的对象)的自动完成功能:

PythonWin IDE with autocomplete

如何在 VS Code 中获得相同的自动完成功能?

我正在使用 Microsoft Python extension .

Python Windows Extensions 有一个名为 COM Makepy 的工具,它显然可以生成 Automation 对象的 Python 表示,但我不知道如何使用它。

更新

显然,Microsoft Python 扩展使用 Jedi用于自动完成。

我已经提交了 issue关于 Github 上的扩展项目。

请注意,通常我在 Python 中有 Intellisense;我只缺少 Intellisense on Automation 对象。

最佳答案

评论

我已经在 VSCode 中确认了你的问题,尽管 IntelliSense 可能工作正常。注意 Ctrl+Space 调用对预定义变量的建议:

enter image description here

但是,默认情况下似乎没有可用于 win32com.client 的公共(public)属性。这可能就是 IntelliSense 似乎不起作用的原因。

测试

拥有installed win32com对于 Python 3.6,我已经在 J​​upyter 笔记本、IPython 控制台和 native Python REPL 中确认了以下代码:

import win32com.client


app = win32com.client.Dispatch("Word.Application")
len(dir(app))
# 55
[x for x in dir(app) if not x.startswith("_")]
# []

本期隐藏属性为not a new .请在另一个环境/IDE 中确认此测试。可能是您的环境或特定版本的 PythonWin 预加载了全局命名空间中的某些变量。

验证以下内容:

引用

关于python - VS 代码和 Python 中自动化对象的自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47900257/

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