在Windows资源管理器中拖放到Python脚本 [英] Drag and drop onto Python script in Windows Explorer
问题描述
我想将我的数据文件拖放到Python脚本中,并将其处理文件并生成输出。 Python脚本接受数据文件的名称作为命令行参数,但Windows资源管理器不允许脚本作为放置目标。
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?
推荐答案
当然可以。从无意识的技术文章Make Python Scripts可以在Windows中删除,您可以通过添加注册表项来添加一个放置处理程序:
Sure. From a mindless technology article called "Make Python Scripts Droppable in Windows", you can add a drop handler by adding a registry key:
这是一个注册表导入文件,你可以这样做。将
复制到.reg文件并运行
(确保您的.py扩展名
映射到Python.File)。
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_ROOT\Python.File\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"
使用与长文件名兼容的WSH丢弃处理程序。要使用短文件名处理程序,请将GUID替换为 86C86720-42A0-1069-A2E8-08002B30309D
。
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该帖子中的评论表示可以启用无控制台Python文件( .pyw
)或编译的Python文件( .pyc
)通过使用
Python.NoConFile
和 Python.CompiledFile
类。
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脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!