在 Windows 资源管理器中拖放到 Python 脚本

Drag and drop onto Python script in Windows Explorer(在 Windows 资源管理器中拖放到 Python 脚本)
本文介绍了在 Windows 资源管理器中拖放到 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

I would like to drag and drop my data file onto a Python script and have it process the file and generate output. The Python script accepts the name of the data file as a command-line parameter, but Windows Explorer doesn't allow the script to be a drop target.

Is there some kind of configuration that needs to be done somewhere for this work?

解决方案

Sure. From a mindless technology article called "Make Python Scripts Droppable in Windows", you can add a drop handler by adding a registry key:

Here’s a registry import file that you can use to do this. Copy the following into a .reg file and run it (Make sure that your .py extensions are mapped to Python.File).

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTPython.FileshellexDropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

This makes Python scripts use the WSH drop handler, which is compatible with long filenames. To use the short filename handler, replace the GUID with 86C86720-42A0-1069-A2E8-08002B30309D.

A comment in that post indicates that one can enable dropping on "no console Python files (.pyw)" or "compiled Python files (.pyc)" by using the Python.NoConFile and Python.CompiledFile classes.

这篇关于在 Windows 资源管理器中拖放到 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Python GTK Drag and Drop - Get URL(Python GTK 拖放 - 获取 URL)
Drag n Drop inside QgraphicsView doesn#39;t work (PyQt)(在 QgraphicsView 内拖放不起作用(PyQt))
How to get dropped file names in PyQt/PySide(如何在 PyQt/PySide 中获取删除的文件名)
In Python, how can I include (not import) one file within another file, macro style, without changing namespace?(在 Python 中,如何在不更改命名空间的情况下在另一个文件中包含(不导入)一个文件,宏样式?)
C Preprocessor Macro equivalent for Python(相当于 Python 的 C 预处理器宏)
Jinja2 inline comments(Jinja2 内联注释)