右键单击命令将参数传递给 python 脚本 [英] Right-click command pass argument to python script

查看:52
本文介绍了右键单击命令将参数传递给 python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作中重写一个 python 脚本,在我右键单击图像序列的文件夹中搜索它的部分功能.我认为我擅长的 python 方面,但右键单击没那么多.我可以在 regedit 中创建一个右键单击按钮,但我不确定如何将参数从我右键单击文件夹的位置传递到我的 python 脚本.我希望参数具有文件夹的路径.我找到了一篇关于这个的帖子,但它对我不起作用..也许是因为他们是在 xp 上制作的??我不确定.(链接如下)

I am rewriting a python script at work and part of what it does is searched inside a folder that I right-click on for image sequences.. The python side of things I think I'm good on, but the right click not so much. I can create a right click button in the regedit but I am unsure of how to pass an argument from where I right-clicked on the folder to my python script. I want the argument to have the path to the folder. I found a post about this but it is not working for me.. maybe because they were making it on xp?? I'm unsure.(Link below)

复制为 Windows 上下文菜单中的路径

我还发现了这段代码片段,我认为它以前被用作 Richt-click 命令..

I also found this snip-it of code which is what I think was being used before as the richt-click command..

@="\"C:\Python26\python.exe\" \"L:\HAL\Func\search\search.py​​\"%L"

@="\"C:\Python26\python.exe\" \"L:\HAL\Func\search\search.py\" %L"

谁能给我解释一下?我知道它首先要运行 python 然后运行脚本..但是@= 和 %L 是什么?我真的很想了解这一点,昨天我花了一整天的时间试图弄清楚,但我只是没有找到太多.预先感谢您的帮助:)

Can anyone explain this to me? I understand it first is going to run python then run the script.. but what is the @= and the %L for? I really want to understand this and I spent all day yesterday trying to figure it out but I'm just not finding much. Thanks in advance for your help :)

这是我也想传递参数的python脚本

This is the python script I want to pass the argument too

import sys
import os


def __main__(argv = sys.argv):

    fileName = argv[1]
    print argv
    print fileName

推荐答案

%L 应该是 %1.也就是说,您正在获取传递给此命令的第一个参数,并将其作为参数传递给您的 Python 脚本.这将是您右键单击的文件的名称.

The %L should probably be %1. That is, you are taking the first argument passed to this command, and passing it as an argument to your Python script. This will be the name of the file you right-clicked.

如果您的 Python 脚本准备接受多个参数(即多个选定的文件),您可以在那里使用 %*.

If your Python script is prepared to accept multiple arguments (i.e. more than one selected file) you could use %* there.

@ 表示命令行不会显示在屏幕上,因此它不会为了运行命令而打开控制台窗口.(不过,如果 Python 脚本生成任何输出,该窗口仍会出现.)

@ at the beginning of the line means the command line won't be displayed on the screen, so it won't open a console window just to run the command. (If the Python script generates any output, the window will still appear, however.)

不确定后面的 = 符号;我没看过,而且很难用谷歌搜索.

Not sure about the = sign following that; I haven't seen it and it's fiendishly hard to Google it.

这篇关于右键单击命令将参数传递给 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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