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

查看:158
本文介绍了右键单击命令将参数传递给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天全站免登陆