从Python访问Windows运行时API
项目描述
Python/WinRT
Windows运行时Python投影(Python/WinRT)允许Python开发者以自然和熟悉的方式从Python直接访问Windows运行时API。
入门
先决条件
- Windows 10,2018年10月更新或更高版本。
- Windows上的Python,版本3.7或更高版本
- pip,版本19或更高版本
安装
Python/WinRT可以通过pip从Python包索引安装。假设pip在路径上,Python/WinRT可以通过以下命令在命令行中安装:
> pip install winrt
您可以通过启动Python并运行以下Python代码片段来测试Python/WinRT是否正确安装。它应该在控制台打印https://github.com/Microsoft/xlang/tree/master/src/tool/python。
import winrt.windows.foundation as wf
u = wf.Uri("https://github.com/")
u2 = u.combine_uri("Microsoft/xlang/tree/master/src/tool/python")
print(str(u2))
有关从Python访问Windows Runtime API的更多信息,请访问Python/WinRT的主页。
有关使用Python/WinRT的完整示例,请参阅xlang GitHub仓库中示例文件夹的WinML教程。