简体   繁体   English

右键单击命令传递参数到python脚本

[英]Right-click command pass argument to python script

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. 我正在重写一个工作中的python脚本,它的一部分工作是在我右键单击以查找图像序列的文件夹中进行搜索。我认为我擅长的python方面,但右键单击的功能不是很多。 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. 我可以在regedit中创建一个右键单击按钮,但是不确定如何将参数从右键单击文件夹的位置传递到python脚本。 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?? 我找到了关于此的帖子,但它对我不起作用..也许是因为他们在xp上发布了该信息? I'm unsure.(Link below) 我不确定。(下面的链接)

Copy as path in windows context menu 在Windows上下文菜单中复制为路径

I also found this snip-it of code which is what I think was being used before as the richt-click command.. 我还发现了这段代码片段,这是我以前认为用作richt-click命令的代码。

@="\\"C:\\Python26\\python.exe\\" \\"L:\\HAL\\Func\\search\\search.py\\" %L" @ =“ \\” C:\\ Python26 \\ python.exe \\“ \\” L:\\ HAL \\ Func \\ search \\ search.py​​ \\“%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? 我了解它首先要运行python然后运行脚本..但是@ =和%L是什么呢? 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 :) 在此先感谢您的帮助 :)

This is the python script I want to pass the argument too 这也是我也想传递参数的python脚本

import sys
import os


def __main__(argv = sys.argv):

    fileName = argv[1]
    print argv
    print fileName

The %L should probably be %1 . %L应该是%1 That is, you are taking the first argument passed to this command, and passing it as an argument to your Python script. 也就是说,您正在采用传递给该命令的第一个参数,并将其作为参数传递给Python脚本。 This will be the name of the file you right-clicked. 这将是您右键单击的文件的名称。

If your Python script is prepared to accept multiple arguments (ie 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.) (但是,如果Python脚本生成任何输出,则该窗口仍会出现。)

Not sure about the = sign following that; 不确定后面的=符号; I haven't seen it and it's fiendishly hard to Google it. 我还没看过,对Google来说很难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过在 Windows 中右键单击“打开方式”上下文菜单将文件传递给 Python,然后在另一个程序中打开 - Pass a file to Python via the Right-Click 'Open With' context menu in windows, to then open in another program 如何通过Windows右键单击上下文菜单将多个参数传递给python程序 - How to pass multiple arguments to a python program via windows right-click context menu 将目录作为命令行参数传递给 python 脚本 - Pass directory to python script as command line argument 将列表作为命令行参数传递给Python脚本 - Pass a list to a Python script as a command line argument 允许右键单击->转到声明和查找引用的Python IDE? - Python IDE that allows for right-click -> Go to Declaration and Find References? 如何在 Python 中模拟右键单击? - How do you simulate a right-click in Python? 将我的python代码转换为Windows应用程序(右键菜单) - convert my python code to windows application (right-click menu) 在 PyQt5 python 中的拆分器句柄上创建右键菜单 - Creating right-click menu on splitter handle in PyQt5 python 如何在 python tkinter 中右键单击将值传递给弹出命令 - how to pass values to popup command on right click in python tkinter python命令行参数并将其作为用户名和密码在脚本中传递 - python command line argument and pass it as username and password in script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM